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

问题描述 投票:1回答:1

我想滚动我的名片视图,但是当我添加ScrollView时,ImageView中的图像会被缩放/拉伸。以下屏幕截图代表了我的问题。

ImageView before adding ScrollView

ImageView after adding Scrollview

我的Activity.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可以正常工作。

我该如何解决此问题?

android android-layout android-imageview android-cardview android-scrollview
1个回答
0
投票

将ImageView scaleType从centerCrop更改为centerInside

© www.soinside.com 2019 - 2024. All rights reserved.