I used the following xml code to draw a drawable image:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle" >
<corners
android:topLeftRadius="30dp"
android:topRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp" />
<solid
android:color="#color/black" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<size
android:width="60dp"
android:height="60dp" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape
android:shape="line">
<stroke
android:width="2dp"
android:color="#color/white" />
</shape>
</rotate>
</item>
</layer-list>
By the above code, I ended up with this image:
Now I have to reduce the length of the white line in the center of the circle. i have used both <size android:height="40dp" /> and <size android:width="40dp" /> on the line and it doesn't do anything. So, how can I reduce the length of the line?
You can try this
Add bottom,top,end & start to your item
<item
android:bottom="10dp"
android:top="10dp"
android:end="10dp"
android:start="10dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape
android:shape="line">
<stroke
android:width="2dp"
android:color="#color/white" />
</shape>
</rotate>
</item>
use this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
<solid android:color="#color/black" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<size
android:width="60dp"
android:height="60dp" />
</shape>
</item>
<item
android:bottom="5dp"
android:end="10dp"
android:start="10dp"
android:top="5dp">
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#color/white" />
</shape>
</rotate>
</item>
</layer-list>
You can adjust padding of rectangle shape to reduce the width of line
You can try this code
<item>
<shape
android:shape="rectangle" >
<corners
android:topLeftRadius="30dp"
android:topRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp" />
<solid
android:color="#color/black" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
<size
android:width="60dp"
android:height="60dp" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape
android:shape="line">
<stroke
android:width="2dp"
android:color="#color/white" />
</shape>
</rotate>
</item>
Related
The drawable is not getting displayed
circle_add.xml in drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="5dp" android:color="#000000"/>
</shape>
</item>
<item>
<shape android:shape="line">
<stroke android:width="5dp" android:color="#000000" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-90">
<shape android:shape="line">
<stroke android:width="5dp" android:color="#000000" />
</shape>
</rotate>
</item>
</layer-list>
I have used it inside the editText
<EditText
android:id="#+id/member_email"
android:layout_width="340dp"
android:layout_height="46dp"
android:background="#d4d4d4"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20dp"
tools:ignore="MissingConstraints"
android:drawableRight="#drawable/circle_add"
tools:layout_editor_absoluteX="36dp"
tools:layout_editor_absoluteY="312dp" />
But it is not getting displayed inside the textbox.
How to make it appear at the end of the textbox.
You didn't define the size of it.
Copy the below codes and try again. it will be shown.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<size
android:height="10dp"
android:width="10dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:width="1dp" android:color="#000000"/>
</shape>
</item>
<item>
<shape android:shape="line">
<stroke android:width="1dp" android:color="#000000" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-90">
<shape android:shape="line">
<stroke android:width="1dp" android:color="#000000" />
</shape>
</rotate>
</item>
</layer-list>
I want to make the background of my layout in android as given below I tried in android studio using layer list and shapes but could not get result anyone expert here please help me how to make the background as given below
I Have tried this code but have not gotten my result. I want a background drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:topRightRadius="15dp" android:topLeftRadius="15dp"
android:bottomRightRadius="15dp"/>
<solid android:color="#color/white"/>
</shape>
I also use Layer list I have no idea how I can get my result
Try with this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--Shadow Layer-->
<item>
<rotate
android:fromDegrees="40"
android:pivotX="100%"
android:pivotY="0%"
android:toDegrees="0">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding
android:bottom="1px"
android:left="1px"
android:right="1px" />
<solid android:color="#01000000" />
</shape>
</rotate>
</item>
<item android:right="10dp">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding
android:bottom="1px"
android:left="1px"
android:right="1px" />
<solid android:color="#01000000" />
</shape>
</item>
<!--===============-->
<item>
<rotate
android:fromDegrees="40"
android:pivotX="100%"
android:pivotY="0%"
android:toDegrees="0">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding android:bottom="1px" />
<solid android:color="#09000000" />
</shape>
</rotate>
</item>
<item android:right="10dp">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding android:bottom="1px" />
<solid android:color="#09000000" />
</shape>
</item>
<!--===============-->
<item>
<rotate
android:fromDegrees="40"
android:pivotX="100%"
android:pivotY="0%"
android:toDegrees="0">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding
android:bottom="1px"
android:left="1px"
android:right="1px" />
<solid android:color="#10000000" />
</shape>
</rotate>
</item>
<item android:right="10dp">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<padding
android:bottom="1px"
android:left="1px"
android:right="1px" />
<solid android:color="#10000000" />
</shape>
</item>
<!--===============-->
<!--ForeGround-->
<item>
<rotate
android:fromDegrees="40"
android:pivotX="100%"
android:pivotY="0%"
android:toDegrees="0">
<shape android:shape="rectangle">
<solid android:color="#d4e5ff" />
</shape>
</rotate>
</item>
<item android:right="10dp">
<shape android:shape="rectangle">
<solid android:color="#d4e5ff" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
I am new to android and I wish to achieve a tooltip with border. Tooltip pointing to left.
i.e: like below with text of choice.
please help me with this, stuck with this for quite sometime now.
I was able to create a tooltip at top righ but how to get it in left ceter_verticle like the diagram.
my code looks like.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="top|right" android:right="10dp">
<rotate android:fromDegrees="45" android:toDegrees="0"
android:pivotX="50%" android:pivotY="0%" >
<shape android:shape="rectangle">
<size android:width="24dp" android:height="24dp" />
<stroke android:color="#android:color/holo_blue_bright" android:width="1dp"/>
</shape>
</rotate>
</item>
<item>
<shape android:shape="rectangle">
<size android:width="206dp" android:height="76dp" />
<solid android:color="#color/white"/>
<stroke android:color="#android:color/holo_blue_bright" android:width="1dp"/>
<corners android:radius="2dp" />
</shape>
</item>
<item android:gravity="top|right" android:right="10dp" android:top="1dp">
<rotate android:fromDegrees="45" android:toDegrees="0"
android:pivotX="50%" android:pivotY="0%" >
<shape android:shape="rectangle">
<size android:width="24dp" android:height="24dp" />
<solid android:color="#color/white"/>
</shape>
</rotate>
</item>
</layer-list>
Try the below code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="16dp"
android:right="16dp"
android:top="17dp"
android:bottom="17dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="15dp" />
</shape>
</item>
<item
android:bottom="345dp"
android:right="360dp"
android:top="345dp">
<rotate
android:fromDegrees="-45"
android:pivotX="10%"
android:pivotY="10%"
android:toDegrees="0">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</rotate>
</item>
<item
android:bottom="350dp"
android:right="350dp"
android:top="350dp">
<rotate
android:fromDegrees="-45"
android:pivotX="1%"
android:pivotY="-5%"
android:toDegrees="0">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</rotate>
</item>
<item
android:bottom="19dp"
android:left="19dp"
android:right="19dp"
android:top="19dp">
<shape android:shape="rectangle">
<solid android:color="#000000" />
<corners android:radius="15dp" />
</shape>
</item>
</layer-list>
I have fair Idea about layer_list referred from here and here
here is my code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#FEBB02" />
<corners android:radius="4dp" />
<size
android:width="40dp"
android:height="20dp" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="10dp"
android:right="10dp"
>
<rotate
android:toDegrees="45"
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape android:shape="rectangle">
<solid android:color="#3F51B5" />
<corners android:radius="2dp" />
</shape>
</rotate>
</item>
This is how it is look line in studio
but when I am applying background of Linearlayout it gives this result
I am expecting corner would be below the pointed as seen in studio.
I think you should try setting the clipToPadding and clipChildren attributes to false, inside the parent view of the linear layout.
Plz change size of Linearlayout to 150dp * 100dp.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item>-->
<!--<scale android:drawable="#drawable/ic_launcher" android:useIntrinsicSizeAsMinimum="true">-->
<!--<!–<shape android:shape="rectangle" android:useLevel="true">–>-->
<!--<!–<solid android:color="#color/red" />–>-->
<!--<!–<size–>-->
<!--<!–android:width="60dp"–>-->
<!--<!–android:height="60dp" />–>-->
<!--<!–</shape>–>-->
<!--</scale>-->
<!--</item>-->
<item
android:bottom="15dp"
android:left="0dp"
android:right="0dp"
android:top="15dp">
<shape android:shape="rectangle">
<solid android:color="#FEBB02" />
<corners android:radius="4dp" />
<size
android:width="150dp"
android:height="70dp" />
</shape>
</item>
<item
android:bottom="15dp"
android:left="40dp"
android:right="40dp"
android:top="15dp"
>
<rotate
android:toDegrees="45"
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape android:shape="rectangle">
<solid android:color="#3F51B5" />
<corners android:radius="2dp" />
<size
android:width="70dp"
android:height="70dp" />
</shape>
</rotate>
</item>
</layer-list>
I need to create some drawables that look like image below, is there a way to do this in xml?
Edit:
I have got this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/darker_gray" />
<corners android:radius="6dp" />
</shape>
</item>
<item
android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="#color/dark_gray" />
<corners android:radius="6dp" />
</shape>
</item>
</layer-list>
it's the same like on the picture without that blue corner and I have no idea how to do that diagonal shape. Now I'm using 9 patch, but since all my other buttons are in xml, I was just wondering if there is some way to write this also in xml
Try this code, i guess this is what you want:
draw.xml
<?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="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#333333" />
<solid android:color="#333333" />
<padding android:bottom="3dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#000000" />
<solid android:color="#000000" />
<padding android:bottom="1dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<size android:width="50dp"
android:height="50dp"/>
<stroke android:color="#android:color/transparent" android:width="0dp"/>
<solid
android:color="#android:color/holo_blue_light" />
<corners android:radius="5dp"/>
</shape>
</rotate>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#android:color/transparent" />
<solid android:color="#android:color/transparent" />
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and in your layout file
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerInParent="true"
android:background="#drawable/draw" >
</RelativeLayout>
You should use layer list to combine multiple drawables below is an example.
You should also check this very complete guide to android drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#585858" />
<solid android:color="#FF9009" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="10dp" android:top="20dp" android:bottom="20dp" android:right="150dp">
<shape
android:shape="oval">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#118C4E" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="150dp" android:top="20dp" android:bottom="20dp" android:right="10dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#C1E1A6" />
<padding android:bottom="1dp"/>
</shape>
</item>
</layer-list>