Java 如何调整按钮图像的大小?
我有下面的布局Java 如何调整按钮图像的大小?,java,android,layout,Java,Android,Layout,我有下面的布局 <Button android:layout_width="fill_parent" android:layout_height="75dp" android:drawableLeft="@drawable/binocular" android:gravity="left|center_vertical"
<Button
android:layout_width="fill_parent"
android:layout_height="75dp"
android:drawableLeft="@drawable/binocular"
android:gravity="left|center_vertical"
android:text="search" />
它看起来像:
这幅画太大了。我只想将图像与左侧的corredct
大小对齐,使其与按钮的高度相匹配
我知道我可以通过代码调整图像的边界。但是我想知道,是否有办法处理布局规范
有一个解决方案:(接受答案)
我想这是正确的,但我不明白将图层列表放在哪里,以及如何在按钮中引用它
有人能帮忙吗?您必须创建新的可绘制xml文件,并在其中放置图层列表代码。例如,button_background.xml
然后设置此可拖动按钮
android:drawableLeft="@drawable/button_background"
在ImageButton
<ImageButton android:id="@+id/iconBtn"
android:layout_width="64dip"
android:layout_height="64dip"
android:src="@drawable/binocular"
android:scaleType="fitCenter"
android:background="#00000000"/>
将ImageButton与这些属性一起使用
<ImageButton
android:id="@+id/button_topleft"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="20dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
/>
在scaleType
失败后,填充在调整图像大小方面起着非常重要的作用
希望这对您有所帮助。尝试使用imagebutton。在res/drawable folderWow中创建一个新的可绘制文件。就这样。谢谢。有人对你的答案投了反对票,我对你的正确答案投了反对票。必须等待10分钟才能接受。Thanks@mcflysoft若答案正确,你们可以用复选标记将其设置为已更正,以关闭问题。快乐编码:)