如何在2个元素之间制作包含标记?

时间:2018-01-07 13:34:01

标签: android xml

我有如下布局。 include标记包含我的片段。我想确保它在我的appbarlayout和bottomnavigationview之间。但目前include标签将延伸到bottomnavigationview之后。我怎样才能确保include标签不会延伸到appbarlayout和bottomnavigationview后面?提前感谢您![My current layout. The include tag extend behind the bottomnavigationview] 1

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    tools:context="co.xtvt.xtvt.ActivityDashboard">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:animateLayoutChanges="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TabItem
                android:id="@+id/tabExploreActivitis"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/activities" />

            <android.support.design.widget.TabItem
                android:id="@+id/tabExplorePeople"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/people" />

            <android.support.design.widget.TabItem
                android:id="@+id/tabExploreGroups"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/groups" />

            <android.support.design.widget.TabItem
                android:id="@+id/tabExplorePosts"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/posts" />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:animateLayoutChanges="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <include layout="@layout/content_dashboard" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        android:layout_gravity="bottom|end"
        app:menu="@menu/bottom_bar_navigation" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginTop="@dimen/fab_margin_top"
        android:layout_marginRight="@dimen/fab_margin_right"
        android:layout_marginLeft="@dimen/fab_margin_left"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        app:srcCompat="@android:drawable/ic_menu_add" />
</android.support.design.widget.CoordinatorLayout>

2 个答案:

答案 0 :(得分:1)

尝试以下代码,我已在您的代码中进行了必要的更改

       <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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"
        tools:context="co.xtvt.xtvt.ActivityDashboard">
    <RelativeLayout
      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"
            android:theme="@style/AppTheme.AppBarOverlay"
            android:animateLayoutChanges="true">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TabItem
                    android:id="@+id/tabExploreActivitis"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/activities" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tabExplorePeople"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/people" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tabExploreGroups"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/groups" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tabExplorePosts"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/posts" />

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

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

        <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:animateLayoutChanges="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <include layout="@layout/content_dashboard" 
          android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomNavigation"/>

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="0dp"
            android:layout_marginStart="0dp"
            android:background="?android:attr/windowBackground"
            android:layout_gravity="bottom|end"
            app:menu="@menu/bottom_bar_navigation" />
        </RelativeLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginTop="@dimen/fab_margin_top"
            android:layout_marginRight="@dimen/fab_margin_right"
            android:layout_marginLeft="@dimen/fab_margin_left"
            android:layout_marginBottom="@dimen/fab_margin_bottom"
            app:srcCompat="@android:drawable/ic_menu_add" />
    </android.support.design.widget.CoordinatorLayout>

答案 1 :(得分:-1)

使用相对布局进行对齐规则。

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:animateLayoutChanges="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<include layout="@layout/content_dashboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomNavigation"
    />
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottomNavigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    android:layout_gravity="bottom|end"
    app:menu="@menu/bottom_bar_navigation" />
</RelativeLayout>