gpt4 book ai didi

android - 在按钮的左侧特别设置图像

转载 作者:行者123 更新时间:2023-11-29 14:50:41 25 4
gpt4 key购买 nike

我想创建一个左侧有图像的 android 按钮。目前我知道在按钮内设置图像的唯一方法是使用 android:background 属性并将其设置为图像,但这样做会拉伸(stretch)图像。我想避免拉伸(stretch)图像并确保它在按钮左侧保持正常大小。

我将如何修改以下代码来实现我的目标?

<ImageButton android:id="@+id/buttonBack"
android:layout_width="80dp"
android:layout_height="30dp"
android:focusable="true"
android:background="@drawable/buttonBack">

最佳答案

这样试试

enter image description here

<!-- For Image to the left of the text use android:drawableLeft tag -->

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/menu"
android:drawableLeft="@drawable/down_arrow"
android:drawablePadding="5dp"
android:text="@string/leftimage" />
<!-- For Image to the Right of the text use android:drawableRight tag -->

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/menu"
android:drawablePadding="5dp"
android:drawableRight="@drawable/down_arrow"
android:text="@string/righttimage" />
</LinearLayout>

关于android - 在按钮的左侧特别设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19277603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com