我使用了constraintLayout
和layout_constraintDimensionRatio="1:1"
(宽度是wrap_content
,身高是0dp
(match_constraint
))
因此,我预计宽度和高度是1:1,但它不起作用。
怎么啦?
我附上了密码和截图。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
android:gravity="center"
android:text="Hello World!11"
app:layout_constraintDimensionRatio="1:1" />
</android.support.constraint.ConstraintLayout>
我引用android开发者关于Constraintlayout布局的网站。https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#DimensionConstraints
比例:你也可以定义一个小部件的一个维度作为另一个小部件的比率。为此,需要至少将一个受限维度设置为0dp (即MATCH_CONSTRAINT),并将属性layout_constraintDimentionRatio设置为给定的比率。例如:
发布于 2018-04-16 15:29:24
作为1.1.0版本,这种情况已经改变了。
现在您可以定义:
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintDimensionRatio="W,1:1"
app:layout_constraintDimensionRatio="H,1:1"
请查看下面的链接,查找有关DimensionConstraints的所有文档:
https://stackoverflow.com/questions/44082305
复制相似问题