简体   繁体   English

Android将三角形可绘制设置为按钮可绘制向左

[英]Android set triangle drawable to Button drawable left

i need some explanation how to set triangle.xml to Button drawable left. 我需要一些解释如何将triangle.xml设置为Button drawable左侧。

    <?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. 所以我有三角形的可绘制对象,当我将其作为按钮的DrawableLeft时不会显示。

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 XML应该如下所示

<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 在您的Activity.java文件中,包括以下行

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM