在ConstraintLayout中,当没有`weight`属性时,android:layout_width="0dp"是什么意思?
In ConstraintLayout, what is the meaning of android:layout_width="0dp", when there is no `weight` attribute?
我有这样的布局:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlayGoogleMaterialIcons">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp">
...
android:layout_width="0dp"
not in the child of 是什么意思
LinearLayout
?
没有weight
属性时android:layout_width="0dp"
是什么意思?
对于 ConstraintLayout
的 children 如果您设置了约束,则 0dp
用于 match_constraint
(取全宽或全高)
Using 0dp, which is the equivalent of "MATCH_CONSTRAINT"
https://developer.android.com/reference/android/support/constraint/ConstraintLayout
例子
<?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/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="text1" />
<TextView
android:id="@+id/tv_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@id/tv_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_1"
tools:text="text2" />
<TextView
android:id="@+id/tv_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_2"
app:layout_constraintTop_toBottomOf="@id/tv_1"
tools:text="text3" />
</android.support.constraint.ConstraintLayout>
在上面的代码(和图像)中,您看到 text1
TextView
宽度是写入文本 text1
所需的宽度
对于 text2 和 text3 TextView
它将整个宽度除以 2,这就是约束所说的
我有这样的布局:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlayGoogleMaterialIcons">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp">
...
android:layout_width="0dp"
not in the child of 是什么意思
LinearLayout
?
没有weight
属性时android:layout_width="0dp"
是什么意思?
对于 ConstraintLayout
的 children 如果您设置了约束,则 0dp
用于 match_constraint
(取全宽或全高)
Using 0dp, which is the equivalent of "MATCH_CONSTRAINT" https://developer.android.com/reference/android/support/constraint/ConstraintLayout
例子
<?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/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="text1" />
<TextView
android:id="@+id/tv_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@id/tv_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_1"
tools:text="text2" />
<TextView
android:id="@+id/tv_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_2"
app:layout_constraintTop_toBottomOf="@id/tv_1"
tools:text="text3" />
</android.support.constraint.ConstraintLayout>
在上面的代码(和图像)中,您看到 text1
TextView
宽度是写入文本 text1
对于 text2 和 text3 TextView
它将整个宽度除以 2,这就是约束所说的