android layout include merge,android

我在ConstraintLayout中使用标签和时遇到问题。

我想创建一个平面视图层次结构(因此Constraints),但仍然有可重用的元素。 所以我在布局中使用并在包含的布局中使用以避免嵌套布局(特别是避免嵌套的ConstraintLayouts)

所以我写了这样的:父布局

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/review_1"

layout="@layout/view_movie_note"

android:layout_width="0dp"

android:layout_height="0dp"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toLeftOf="@+id/review_2"/>

layout="@layout/view_movie_note"

android:id="@+id/review_2"

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_marginLeft="7dp"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toRightOf="@+id/review_1"

app:layout_constraintRight_toRightOf="parent"

/>

这个view_movie_note:

android:id="@+id/note_origin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="15dp"

android:layout_marginStart="5dp"

app:layout_constraintStart_toStartOf="@+id/cardView2"

app:layout_constraintTop_toTopOf="parent"

android:layout_marginLeft="5dp" />

android:id="@+id/five_star_view_container"

android:layout_width="0dp"

android:layout_height="52dp"

android:layout_marginBottom="8dp"

android:layout_marginTop="10dp"

android:elevation="3dp"

app:cardUseCompatPadding="true"

app:contentPaddingTop="22dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHeight_min="52dp"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/note_origin">

android:id="@+id/five_star_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal" />

android:id="@+id/cardView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

app:cardBackgroundColor="@color/colorPrimary"

app:contentPaddingLeft="15dp"

app:contentPaddingRight="15dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="@+id/note_origin">

android:id="@+id/grade"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="12sp" />

我期待着这一点

dc7a33a707e38d19333abb5548c1414f.png

相反,我得到了这个

da41a0cee07001b4b6cc581552cdc496.png

很明显,我在标记中的约束被包含的布局中的约束覆盖。

这是预期的行为吗? 如果是,我们应该如何使用和ConstraintLayout保持平面布局?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值