我正在尝试在父元素中居中显示一张图片,它的尺寸比例为1220:1000,并且最大高度为300dp(即使在大屏幕下也要保持图片较小)。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1220:1000"
app:layout_constraintHeight_max="200dp" ==> This line break the ratio (the image is not displayed)
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
app:layout_constraintHeight_max
属性破坏了比例关系。有没有什么方法可以解决?
app:layout_constraintDimensionRatio="W,1220:1000"
与app:layout_constraintHeight_max="300dp"
- Bogy2.0.3
中,似乎必须使用H
代替W
。 - wrozwad