【发布时间】:2018-06-02 19:29:30
【问题描述】:
在我的约束布局中,我有一个正方形的 ImageView。它的宽度由 GuideLines 定义:
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintTop_toTopOf="@id/guideline_h1"
app:layout_constraintLeft_toLeftOf="@id/guideline100"
app:layout_constraintRight_toLeftOf="@+id/guideline010"
app:srcCompat="@drawable/choice04"/>
当然,我现在需要定义它的 constraintBottom 参数。但是,使用其他指南并不是一个好方法,因为在不同的屏幕尺寸上,% 值可能会改变比率。由于图像是一个正方形,我需要我的 ImageView 具有屏幕的 5% 到 45% 的宽度,这可以通过指南实现,并且它的高度是相同的。
【问题讨论】:
-
分享您的整个布局和所需的输出
-
见this ^F
ratio
标签: android layout height width