android triangle drawablw xml

こ雲淡風輕ζ 提交于 2020-01-21 12:24:50

问题


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


回答1:


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.




回答2:


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




回答3:


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>


来源:https://stackoverflow.com/questions/35618650/android-triangle-drawablw-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!