0

我需要将活动内部的片段(以约束布局编写)连接到 AppBar(以协调器布局编写,在约束布局之外)。问题是片段从父级开始,而不是在 AppBar 下方。我最好的想法是在活动中放置一个指南,这样我就可以将片段约束到指南而不是 AppBar。问题是我必须对我实现该片段的每个活动都使用相同的指导方针,并且我想避免这种情况。这一切基本上只是为了让我可以像现在一样重用片段,而不需要更改它的尺寸以使其适合活动的一部分。这是 XML 代码的一部分。我只是在寻找更好的解决方案,其中片段将真正可重用。

   <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <include layout="@layout/item_view_toolbar" />

        </android.support.design.widget.AppBarLayout>


        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
   <fragment
            android:id="@+id/profile_fragment"
            android:name="xxx.contractor.ui.fragment.ProfileFragment_"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/view"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
4

0 回答 0