Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 缩放图像以适应ImageButton高度并保持Apsect比率_Android_Android Layout_Scale_Android Imagebutton - Fatal编程技术网

Android 缩放图像以适应ImageButton高度并保持Apsect比率

Android 缩放图像以适应ImageButton高度并保持Apsect比率,android,android-layout,scale,android-imagebutton,Android,Android Layout,Scale,Android Imagebutton,我怎样才能回答上述问题?当前图像看起来太小了。我想我可以通过设置填充父对象的高度和包裹内容的宽度来解决这个问题,但这并没有实现,因为宽度是原始图像的大小,而不是缩放版本的大小。我怎样才能解决这个问题 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match

我怎样才能回答上述问题?当前图像看起来太小了。我想我可以通过设置填充父对象的高度和包裹内容的宽度来解决这个问题,但这并没有实现,因为宽度是原始图像的大小,而不是缩放版本的大小。我怎样才能解决这个问题

<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:src="@drawable/androidImage"
        android:scaleType="center"
        android:layout_weight="1"/>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="horizontal"
        android:background="#4CAF50"
        android:layout_weight="0">
        <TextView
            android:id="@+id/textSample"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_centerInParent="true"
            android:layout_alignParentLeft="true"
            android:text="Test"
            android:textColor="#FFFFFF"
            android:textSize="48sp"
            android:padding="20dp"/>
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_margin="10dp"
            android:layout_centerInParent="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_mood_white"
            android:scaleType="centerInside"
            android:background="#100FFFFFF"/>
    </RelativeLayout>
</LinearLayout>

使用属性

android:scaleType="fitXY".

使用android:scaleType=“centerCrop”代替android:scaleType=“centerInside”仍然没有区别。与按钮相比,图像仍然太小。