我将此ConstraintLayout设置为三个孩子。出于某种原因,nav_banner子不受我施加的约束的影响:
nav_banner是顶部的白色条,nav_header是横幅后面的灰色方块(以蓝色突出显示),RecyclerView是包含项目的较暗方块:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/nav_header"
layout="@layout/nav_header" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_menu_list"
app:layout_constraintTop_toBottomOf="@id/nav_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp" />
<include
android:id="@+id/nav_banner"
app:layout_constraintTop_toBottomOf="@id/nav_header"
layout="@layout/nav_banner" />
</android.support.constraint.ConstraintLayout>
{app:layout_constraintTop_toBottomOf =“ @ id / nav_header”}行正确地将RecyclerView放置在标题下方。
添加到nav_banner的同一行没有可见效果。我尝试过向横幅添加各种不同的约束,但是它根本没有动,只是停留在ConstraintLayout的根位置。
我想通过编辑源代码来解决此问题。任何建议将不胜感激!
这是nav_banner.axml的源代码,如果您需要检查的话
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#eeeeee">
<ImageView
android:id="@+id/bannerIcon"
android:src="@drawable/ic_check_green_500_24dp"
android:layout_marginLeft="16dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/bannerText"
android:text="Sample text"
android:gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"/>
<ImageButton
android:id="@+id/dismissButton"
android:src="@drawable/ic_close_circle_outline"
android:background="?android:selectableItemBackgroundBorderless"
android:layout_gravity="center"
android:paddingRight="8dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"/>
</LinearLayout>