gpt4 book ai didi

imageview - 在 ConstraintLayout 中有一个具有相同宽度和高度的 ImageView

转载 作者:行者123 更新时间:2023-12-03 21:22:11 27 4
gpt4 key购买 nike

我们如何使 ImageView 的宽度和高度等于父 ConstraintLayout 的宽度?所以它显示一个全宽的方形 ImageView。

通常如何设置某个小部件的高度等于其他小部件的宽度?

最佳答案

以下布局将在父级 ConstraintLayout 的中心放置一个方形蓝色图像。 .关键是app:layout_constraintDimensionRatio="1:1" .引用 documentation详情。

You can also define one dimension of a widget as a ratio of the other one. In order to do that, you need to have at least one constrained dimension be set to 0dp (i.e., MATCH_CONSTRAINT), and set the attribute layout_constraintDimensionRatio to a given ratio.


<android.support.constraint.ConstraintLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_blue_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

关于imageview - 在 ConstraintLayout 中有一个具有相同宽度和高度的 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52569240/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com