android怎么变换按钮图片大小,android – 如何调整按钮内的图像大小
时间: 2024-05-13 19:18:09 浏览: 15
你可以通过设置按钮的背景来调整按钮内的图像大小。具体步骤如下:
1. 在drawable文件夹中创建一个新的XML文件,例如button_background.xml。
2. 在XML文件中添加以下代码:
```
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_image"
android:width="50dp"
android:height="50dp"
android:gravity="center"/>
</layer-list>
```
其中,@drawable/button_image是你想要设置的按钮图片,android:width和android:height分别是你想要设置的宽度和高度,android:gravity是图像的对齐方式,这里设置为居中。
3. 在你的布局文件中,将按钮的背景设置为button_background.xml,例如:
```
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_background"
android:text="My Button" />
```
这样就可以调整按钮内的图像大小了。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)