This question already has answers here:
Making a triangle shape using XML definitions?
(20 answers)
Closed 8 years ago.
In XML I'm attempting to draw a drop down triangle to be used as a background for a button but cant seem to get my head round the rotate XML tags.
Here's my XML code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="80%"
android:pivotY="20%">
<shape
android:shape="rectangle" >
<solid
android:color="#FFCC00" />
</shape>
</rotate>
</item>
</layer-list>
And here's the outcome of the XML:
Any ideas are appreciated.
i can draw triangle shape using XML
triangle .xml
<?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="-40%"
android:pivotY="87%"
android:toDegrees="45" >
<shape android:shape="rectangle" >
<stroke
android:width="10dp"
android:color="#00000000" />
<solid android:color="#00ACED" />
</shape>
</rotate>
</item>
</layer-list>
Try out the Below
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="90%"
android:pivotY="-50%" >
<shape
android:shape="rectangle" >
<stroke android:color="#android:color/transparent" android:width="1dp"/>
<solid
android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
Related
This question already has answers here:
android triangle drawablw xml
(3 answers)
Closed 5 years ago.
How to create shape in android using xml? and can we arrange those triangles as circle?
Try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/rightArrow">
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#android:color/transparent" android:width="10dp"/>
<solid
android:color="#000000" />
</shape>
</rotate>
</item>
</layer-list>
For the desired direction of triangle you can play with the degrees and pivotx/y points
e.g
<rotate
android:fromDegrees="220"
android:toDegrees="0"
android:pivotX="35%"
android:pivotY="5%" >
<shape
android:shape="rectangle" >
<stroke android:color="#000000" android:width="1dp"/>
<solid
android:color="#000000" />
</shape>
</rotate>
will give you 'v' shaped triangle
alternate for rotate
this property also given v shape triangle
android:rotation="180"
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>
I want to draw an equilateral triangle.I have checked but it is inverted.I want a triangle that looks like the image below.
Triangle:
triangle_shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#fff" android:width="1dp"/>
<solid
android:color="#000" />
</shape>
</rotate>
</item>
</layer-list>
Currently it looks like this..
Usign Vector drawable you can achieved your shape like below:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<group android:name="triableGroup">
<path
android:name="triangle"
android:fillColor="#color/color_start_color_back"
android:pathData="m 50,0 l 50,50 -100,0 z" />
</group>
</vector>
Output:
I hope its helps you.
Try this way it will work
<?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="-40%"
android:pivotY="87%"
android:toDegrees="45" >
<shape android:shape="rectangle" >
<stroke
android:width="10dp"
android:color="#00000000" />
<solid android:color="#00ACED" />
</shape>
</rotate>
</item>
</layer-list>
OUTPUT
I have found out the way to make it look like an up facing triangle.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="270%"
android:pivotY="70%" >
<shape
android:shape="rectangle" >
<stroke android:color="#000000" android:width="1dp"/>
<solid
android:color="#000000" />
</shape>
</rotate>
</item>
</layer-list>
i need some explanation how to set triangle.xml to Button drawable left.
<?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="13%"
android:pivotY="-40%"
android:toDegrees="45" >
<shape
android:shape="rectangle" >
<stroke
android:width="10dp"
android:color="#F000" />
<solid android:color="#color/Lime" />
</shape>
</rotate>
</item>
</layer-list>
So i have drawable of triangle and it wont show up when i put it as DrawableLeft of button.
is there are other way to make triangle as pure shape or some method to make it work?
Your Button XML should look like below
<Button
android:id="#+id/YourButton"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Name of the button"
android:drawableLeft="#drawable/drawablefilename"
android:onClick="listener"
>
</Button>
In your Activity.java file, include this line
btnName.setCompoundDrawablesWithIntrinsicBounds( R.drawable.drawablefilename, 0, 0, 0);
It might wor
My bad found my problem. It needs to set size.
<?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="13%"
android:pivotY="-40%"
android:toDegrees="45" >
<shape
android:shape="rectangle" >
****<size android:width="15dp" android:height="15dp"/>****
<stroke
android:width="10dp"
android:color="#F000" />
<solid android:color="#color/Lime" />
</shape>
</rotate>
</item>
</layer-list>
I have a shape.xml file something like this :
<?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="100%"
android:toDegrees="-45" >
<shape android:shape="rectangle" >
<stroke
android:layout_width="match_parent"
android:color="#color/red" />
<solid android:color="#color/red" />
</shape>
</rotate>
</item>
</layer-list>
I have to change the attributes of this file dynamically. I know that i have to use GradientDrawable but i am not be able to get the exact configuration as defined in this file. Can anyone help.