在Android上使用scaletype centerCrop时,如何调整ImageView的裁剪量?

时间:2020-04-14 22:02:27

标签: android xml imageview scaletype

我在LinearLayout中有一个ImageView(PhotoView),我正在应用scaletype中心裁切,但是裁切了太多,看起来也放大了。我该如何解决呢?

       <LinearLayout
           android:id="@+id/photoViewContainer"
           android:layout_width="wrap_content"
           android:layout_height="@dimen/flexible_space_image_height"
           android:background="@android:color/holo_purple"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintTop_toTopOf="parent"
           app:layout_constraintVertical_bias="0.0">
               <com.github.chrisbanes.photoview.PhotoView
                   android:id="@+id/mainImageView"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:scaleType="centerCrop"
                   android:adjustViewBounds="true"
                   android:background="@android:color/black" />
       </LinearLayout>

1 个答案:

答案 0 :(得分:0)

我不确定您是否可以控制裁剪,但是使用scaletype="fitXY"并提供一些填充对我有用。

<com.github.chrisbanes.photoview.PhotoView
                   android:id="@+id/mainImageView"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:scaleType="fitXY"
                   android:padding="16dp"
                   android:adjustViewBounds="true"
                   android:background="@android:color/black" />

在这种情况下,scaletype="fitXY"会将图像压缩到屏幕大小,并对其进行填充以使其居中放置。
还有一个我听说过的hack,其中您用负填充替换了填充,这会缩小图像,但我没有尝试过。

相关问题