如何调整图像大小按钮?

时间:2016-05-20 01:57:53

标签: android image android-studio

所以我有ImageButton,但图像非常适合它。我尝试了android:scaleType="center",但由于图片居中但却太小而且尝试fitXY但结果相同而失败了。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f1e8e8"
    tools:context="com.example.bassam.myapplication123.MainActivity">
    <ImageButton android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:padding="100dip"
        android:background="#ffffff"
        android:src="@drawable/Work"
        android:scaleType="fitXY"
        ></ImageButton>
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

如果我理解你的关注是正确的,你只需要将图像缩放到ImageButton本身的大小,只需使用

android:scaleType="fitCenter"

根据ImageButton的大小调整图像。尝试一下,让我知道它是否有效。干杯! :)