Android 为什么添加ScrollView时ImageView图像会缩放?

Android 为什么添加ScrollView时ImageView图像会缩放?,android,android-layout,android-imageview,android-cardview,android-scrollview,Android,Android Layout,Android Imageview,Android Cardview,Android Scrollview,我想滚动我的卡片视图,但当我添加了滚动视图后,ImageView中的图像被缩放/拉伸。下面的截图代表了我的问题 我的活动.xml <LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:to

我想滚动我的卡片视图,但当我添加了滚动视图后,ImageView中的图像被缩放/拉伸。下面的截图代表了我的问题

我的活动.xml

<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OrbitPostViewer">

<androidx.cardview.widget.CardView
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ScrollView
            android:fillViewport="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:padding="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_marginTop="10dp"
                android:id="@+id/orbitPostSharedImg"
                android:layout_gravity="center_horizontal"
                android:scaleType="centerCrop"
                android:src="@drawable/rabindranath_tagore"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

</LinearLayout>
        </ScrollView>
    </androidx.cardview.widget.CardView>
</LinearLayout>

如上面代码所示。我还将fillViewport添加到了true,但它仍然不起作用。移除滚动视图时,CardView工作正常,但无法滚动


如何解决此问题?

将ImageView比例类型从
centerCrop
更改为
centerInside
您可以对包含ImageView的线性布局使用
android:layout\u gravity=“center”
,并将比例类型更改为
centerInside
fitCenter

<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.cardview.widget.CardView
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ScrollView
            android:fillViewport="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="vertical"
                android:padding="10dp"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_marginTop="10dp"
                    android:id="@+id/orbitPostSharedImg"
                    android:layout_gravity="center_horizontal"
                    android:scaleType="centerInside"
                    android:src="@drawable/rabindranath_tagore"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

            </LinearLayout>
        </ScrollView>
    </androidx.cardview.widget.CardView>
</LinearLayout>


这是实际图像大小吗?图像大小为1071 x 1500像素。但不同大小的图像在图像视图上的行为也相同。