Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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 以相同的宽度和高度比在不同的屏幕尺寸上调整ImageView/ImageButton的大小_Android_Android Layout_Android Imageview - Fatal编程技术网

Android 以相同的宽度和高度比在不同的屏幕尺寸上调整ImageView/ImageButton的大小

Android 以相同的宽度和高度比在不同的屏幕尺寸上调整ImageView/ImageButton的大小,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,我有由4个图像视图/图像按钮组成的线性布局。所有图像都具有相同的宽度和高度。我希望此布局始终适合父级的宽度,并且所有图像都具有相同的纵横比(宽度和高度): 我试过这个: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Imag

我有由4个图像视图/图像按钮组成的线性布局。所有图像都具有相同的宽度和高度。我希望此布局始终适合父级的宽度,并且所有图像都具有相同的纵横比(宽度和高度):

我试过这个:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item_background"
            android:layout_weight="1"
            android:adjustViewBounds="true"/>
    // All 4 images are the same 
</LinearLayout>

//所有4个图像都是相同的
问题是陆地/肖像中的宽度和高度之比不一样。例如,在横向模式下,图像仅在x轴上拉伸,而不在y轴上拉伸:

我不想只编写这样的UI代码,我希望您能帮助我找到一种用XML实现这一点的方法

编辑:

在将android:scaleType=“fitXY”添加到图像后,我得到以下信息:

正如你所看到的,这不是一个很好的解决我想要的问题的方法。

你可以使用

android:scaleType="fitXY" 

它将适合图像视图中的资源。

使用
android:layout\u width=“match\u parent”
android:scaleType=“fit\u CENTER”
这可能是正常的,因为线性布局的方向是“水平的”


要解决您的问题,您可以使用上面回答的代码。

有一个为android开发的.9.png图像格式,它可能会帮助您解决这个问题,这是来自android开发者网站的链接。

我将所有图像的布局权重设置为1。所以这不是一个问题。我认为上面的代码在横向模式下很好,我试过了,没问题。android:adjustViewBounds=“true”保留图像的纵横比