在我的应用程序中有 3 个按钮
(屏幕截图位于底部)。现在我想在第一个 Button
(底部的图像)上设置一个 AnimatedDrawable
(一根手指)。我使用的是 LinearLayout,按钮的背景只是一种颜色(不可绘制)。
我试过这个:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/black"/>
</shape>
</item>
<item android:drawable="@drawable/finger"></item>
</layer-list>
并将layer-list
设置为Button
的背景,但手指与Button
一样大。我还尝试在 LinearLayout
中使用 RelativeLayout
,但无法设置 Buttons
的 weight
。由于 Button
上的文本,我无法使用 ImageButton
。那么有可能解决这个问题吗?
问候尼尔斯
最佳答案
试试这个代码:
<Button
android:id="@+id/Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:drawableRight="@android:drawable/ic_menu_directions"
android:text="Button" />
您可以从drawable中选择任何图像,而不是“@android:drawable/ic_menu_directions”
关于Android:设置可绘制按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24183663/