Making android custom drawable - android

How can one create such a drawable that will be matching height of given layout ? I know I have to create a some sort of multiple shapes within one drawable but I am kinda lost in this.

Try layer-list of 2 oval shapes and a line. Then set as the background of your view. I'm not sure if it works.
You can also use 9 patch: read this

It should work with xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="4dp">
<item>
<rotate android:fromDegrees="90" android:gravity="center_horizontal" android:toDegrees="90">
<shape android:shape="line">
<stroke android:color="#000000" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:gravity="center_horizontal|top" android:height="8dp" android:width="8dp">
<shape android:shape="oval">
<solid android:color="#000000"/>
</shape>
</item>
<item android:gravity="center_horizontal|bottom" android:height="4dp" android:width="4dp">
<shape android:shape="oval">
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>

Related

How do you create a layer-list with two solids next to each other?

I'm trying to create a drawable with two shapes next to each other using layer-list, how would I do it?
You can use the following code to have the drawable you want(Change the colors and height as you want)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape android:shape="rectangle">
<size
android:width="5dp"
android:height="5dp" />
<solid android:color="#color/colorAccent"/>
</shape>
</item>
<item android:gravity="right">
<shape android:shape="rectangle">
<size
android:width="1dp"
android:height="5dp" />
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
</layer-list>

trouble with layer-list in xml drawable?

I am trying to design a layout using xml. it's a chat bubble layout. I just need a shape to be place after a shape. basically i am using 2 rectangles 1 rectangle rotated by 45 degree. i need tilted rectangle to placed after a normal rectangle.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="-45"
android:pivotX="0%"
android:pivotY="0%"
android:toDegrees="0" >
<shape android:shape="rectangle" >
<solid android:color="#color/chat_incoming_color" />
</shape>
</rotate>
</item>
<item android:left="16dp">
<shape android:shape="rectangle" >
<solid android:color="#color/chat_incoming_color" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
http://imgur.com/j556772
image is shown in the link in that image first part is ok but second layout's background should be made accordingly..
Try this I hope it will help you to understand your problem.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate android:fromDegrees="45"
android:pivotX="-35%"
android:pivotY="91%"
android:toDegrees="0">
<shape>
<solid android:color="#android:color/darker_gray"/>
</shape>
</rotate>
</item>
<item android:left="16dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray"/>
<corners android:radius="4dp"/>
</shape>
</item>
</layer-list>

How can I create a vertical line in a drawable xml? Android

Is there a way to make a drawable that draws a vertical line? So far I have a horizontal line that draws this:
current code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/object_switcher_background" />
<item android:left="0dp"
android:right="250dp">
<shape android:shape="line">
<stroke android:color="#color/c19"
android:width="2dp"/>
<size android:width="40dp"/>
</shape>
</item>
<item android:left="50dp"
android:bottom="50dp"
android:top="75dp"
android:right="150dp">
<shape android:shape="line">
<stroke android:color="#color/c19"
android:width="2dp"
android:rotation="90"/>
<size android:width="40dp"/>
</shape>
</item>
</layer-list>
How can I manipulate this to make it look like this?
You could do this by nesting your second item inside a rotate item.
you can do that using rotate item: the below code defines a white background with a vertical divider using only xml drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/white" />
</shape>
</item>
<item>
<rotate android:fromDegrees="90">
<shape android:shape="line">
<stroke
android:width="1dp"
android:color="#android:color/darker_gray" />
</shape>
</rotate>
</item>
I'm not sure why you need a drawable for this.
This can also be done by using a simple view and adjusting its height, width and position according to your needs. For example:
<View
android:layout_width="1dp"
android:background="#color/grey_text_color"
android:layout_height="match_parent"/>

XML 45° Effect-Overlay

I'm just struggling around with a simple effect, that I would like to create directly within the XML layout file....
As you can see I just want to create a 45° overlay effect. But I'm not able to do so. Maybe you can lead me into the right direction...
Code of round linearlayout (left side):
<LinearLayout
android:layout_width="match_parent" android:layout_alignParentBottom="true"
android:layout_height="95dp" android:background="#drawable/semicircle_layout">
</LinearLayout>
semicircle_layout
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#393a3f"/>
</shape>
</item>
<item android:top="1dp">
<shape android:shape="oval">
<solid android:color="#27262c"/>
</shape>
</item>
<item android:top="2dp">
<shape android:shape="oval">
<gradient android:angle="45" android:startColor="#000000" android:endColor="#000000"/>
</shape>
</item>
</layer-list>
Any help would be greatly appreciated.
Thanks.

How to define a rectangle with a circle at the end using Android XML definitions

Is it possible to define a shape like shown on the following image:
I tried a layer-list but I could not find a solution close to what I am looking for.
I want to use the resulting shape as a background image to a RelativeLayout with a transparency.
Any hints are appreciated! Thank you.
Here is the shape you asked for:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<size
android:width="250dp"
android:height="100dp" />
<solid android:color="#ffffff" />
</shape>
</item>
<item
android:top="0dp">
<shape android:shape="line">
<stroke
android:width="25dp"
android:color="#000000" />
</shape>
</item>
<item
android:right="0dp"
android:left="150dp">
<shape android:shape="oval">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Screenshot:

Categories

Resources