Android ImageView的高度与参考线的宽度相同
在约束布局中,我有一个正方形的ImageView。其宽度由以下指南定义:Android ImageView的高度与参考线的宽度相同,android,layout,height,width,Android,Layout,Height,Width,在约束布局中,我有一个正方形的ImageView。其宽度由以下指南定义: <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"
<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%,这是我可以通过指南实现的,并且它的高度是相同的。来自@pskink的评论是我想要的。行:
app:layout_constraintDimensionRatio="1:1"
成功了。分享您的整个布局和所需输出参见^F
ratio