Android 图像拉伸

Android 图像拉伸,android,imageview,scale,android-linearlayout,Android,Imageview,Scale,Android Linearlayout,API 7(2.1) 我正在为我的应用程序的drawable hdpi文件夹实现高分辨率图像 沿着我的屏幕底部,我有一个填充宽度的线性布局。在内部,我有3个线性布局,权重为1。在这些里面,我有一个图像视图。实际上,我有3个大小相等的空间来放置3个图像 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android

API 7(2.1)

我正在为我的应用程序的drawable hdpi文件夹实现高分辨率图像

沿着我的屏幕底部,我有一个填充宽度的线性布局。在内部,我有3个线性布局,权重为1。在这些里面,我有一个图像视图。实际上,我有3个大小相等的空间来放置3个图像

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">   
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image1"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:padding="0dip">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image2"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image3"
                />
        </LinearLayout>
    </LinearLayout>

当手机处于横向模式时,一切看起来都很好

当手机处于纵向模式时,图像会缩小,因为其宽度对于屏幕上1/3的空间来说太宽。图像看起来仍然很好

我的问题是:

我的图像可以很好地缩放,但似乎环绕每个图像的线性布局不会缩放其高度

在横向模式下,环绕图像的线性布局的顶部和底部共享一条边。这意味着,ImageView的顶部与环绕它的线性布局的顶部对齐,ImageView的底部与环绕它的线性布局的底部对齐。换句话说,LinearLayout的高度==ImageView的高度

在纵向模式下,环绕图像的线性布局的顶部和底部与图像的顶部和底部之间有一组空间,几乎就像有填充一样。换句话说,线性布局的高度>图像视图的高度。这是不可取的

有什么想法吗


这几乎就像是调整线性布局和图像视图的大小,然后挤压图像视图使其适合,然后不调整线性布局的大小…

我知道这并没有回答您提出的问题,但是,当设备方向发生变化时,通过将线性布局的方向更改为垂直,似乎可以更好地避免多个问题。我相信你可以用一个OrientationEventListener做到这一点。

你可以尝试为两个方向设计单独的布局。在项目的res文件夹中,创建一个子文件夹,名为
layoutland
。复制或创建具有相同名称的新布局。这样,您就可以完全控制任何方向的布局

由于您使用的是
android:layout\u weight=“1”
,因此线性布局不应该平均分割空间,因此会出现额外的空间

编辑: 当LinerLayout设置了权重时,似乎是ImageView扩展了其高度。将此行添加到每个ImageView:

android:adjustViewBounds=“true”


我想最好为肖像模式设计另一个布局。
纵向和横向模式不要使用相同的布局。对于纵向和横向模式,最好有不同的布局,这样设计的控制权就掌握在我们手中。

有人吗?我现在在多个地方遇到了这个问题。a)你在测试什么?和b)如何将
线性布局对齐屏幕底部,因为这可能会影响其高度。@安德鲁:要使左右间距相等,可以使用android:layout\u marginLeft或android:layout\u marginRight属性。您也可以使用填充。左右两侧应显示相等的空间,是的。但由于高度是包裹内容,因此上方不应出现额外的空间。这是我的问题。我必须在我的系统上尝试。我也遇到过类似的问题,理论上的布局应该有效,但实际上不行,所以我必须进行实验并找到解决办法。