android triangle drawablw xml

2019-02-27 02:25发布

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: enter image description here

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..

enter image description here

3条回答
手持菜刀,她持情操
2楼-- · 2019-02-27 02:39

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

enter image description here

查看更多
Bombasti
3楼-- · 2019-02-27 02:41

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>
查看更多
女痞
4楼-- · 2019-02-27 02:44

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:

enter image description here

I hope its helps you.

查看更多
登录 后发表回答