【发布时间】:2018-03-27 23:23:17
【问题描述】:
我正在使用 ConstraintLayout 使我的应用能够响应不同的屏幕尺寸。
我想使用比率来调整小部件的大小。 所以要使用比率,我必须将我的宽度和高度设置为 match_constraints。
所以我正在做的是:
<ImageView
android:id="@+id/my_img"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="150dp"
android:layout_marginStart="250dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:src="@drawable/img_test"
app:layout_constraintBottom_toTopOf="@+id/bot_img"
app:layout_constraintDimensionRatio="h,125:50"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_img" />
所以我将使用边距和比率(以 dp 为单位)来设置我的 img 大小。 问题是当我使用不同的屏幕尺寸时,我的 img 不会保持我想要的确切比例。
你能帮帮我吗?我使用 ConstraintLayout 对吗?非常感谢
【问题讨论】:
标签: android android-studio responsive-design responsive android-constraintlayout