Android ImageView宽度与父级不匹配

Android ImageView宽度与父级不匹配,android,android-layout,imageview,Android,Android Layout,Imageview,我拥有的内容:滚动视图,在它里面 LinearLayout (orientation=“vertical”, 布局\u width=“匹配父项”, layout_height=“wrap_content”) 里面 ImageView (layout\u width=“匹配父项”, 布局高度=“包装内容”)和 TextView 我想要的:ImageView应该保持纵横比和数学父宽度,以及ImageView下面的文本 我使用了ImageView参数的不同组合:adjustViewBounds tru

我拥有的内容:
滚动视图
,在它里面
LinearLayout

orientation=“vertical”,
布局\u width=“匹配父项”,
layout_height=“wrap_content”

里面

ImageView

layout\u width=“匹配父项”,
布局高度=“包装内容”
)和

TextView

我想要的:
ImageView
应该保持纵横比和数学父宽度,以及
ImageView
下面的文本

我使用了
ImageView参数的不同组合
adjustViewBounds true/false
和所有
scaleType
,但我无法得到我想要的:

  • 如果我使用scaleType centerCrop-图像裁剪时的顶部和底部
  • 如果我使用scaleType center-左、右空格
  • 如果我使用scaleType fitXY-image不保持纵横比
  • 因此,我无法使图像更高,如何修复它?

    尝试以下方法:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
    <LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical"
           >
    <ImageView
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:id="@+id/iv"
            android:background="#f0f"
            />  
    <TextView
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:text="Always work!!"
               android:gravity="center"
               android:textSize="26sp"
               />
    </LinearLayout>
    </ScrollView>
    
    
    
    注意:如果
    scaleType
    没有帮助,请尝试使用
    android:background=“”
    代替
    android:src=“”


    您是否可以发布您的布局xml,或者发布一个屏幕,显示您得到的内容及其外观?阅读代码比通过描述获取代码要容易得多……如果图像比父图像小,该怎么办?是否应该扩大规模?这将扭曲图像。请尝试使用ImageView的
    scaleType=“fitCenter”