【问题标题】:android:scaleType="centerInside" not respected in androidx ConstraintLayout?android:scaleType="centerInside" 在 androidx ConstraintLayout 中不受尊重?
【发布时间】:2020-05-27 11:55:51
【问题描述】:

我有两个相同的约束布局,除了一个是Android X,另一个是support

Android X 版本似乎不尊重缩放属性android:scaleType="centerInside",因为当我将手机倾斜到横向模式时,不尊重 ImageView 的纵横比。

support

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#252525">


    <!-- list item -->
    <ImageView
        android:id="@+id/imageView2"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:adjustViewBounds="true"
        android:scaleType="centerInside"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        app:srcCompat="@drawable/background_listening"
        />

</android.support.constraint.ConstraintLayout>

androidx

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#252525">

    <!-- list item -->
    <ImageView
        android:id="@+id/imageView2"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:adjustViewBounds="true"
        android:scaleType="centerInside"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        android:background="@drawable/ic_background_unselected"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

这两种布局有什么明显的区别吗?

谢谢

【问题讨论】:

    标签: android android-constraintlayout androidx


    【解决方案1】:

    在androidX中删除

    android:adjustViewBounds="true"
    

    来自 ImageView

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 2010-10-05
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2019-04-06
      • 2012-07-25
      相关资源
      最近更新 更多