来自viewPager的片段隐藏在操作栏

时间:2016-04-13 16:05:56

标签: android android-layout listview android-fragments

其实我正在尝试构建一个listView / recyclerView。在滚动列表时,操作栏得到隐藏,其中操作栏是工具栏,但列表视图的某些部分隐藏在选项卡后面。这里我使用AppBarLayout和工具栏有app:layout_scrollFlags =“scroll | enterAlways”,在我的recylerview中有app:layout_behavior =“@ string / appbar_scrolling_view_behavior”行为。我可以使用线性布局,但问题是工具栏的滑动,AppBarLayout必须是CoordinatorLayout的子项。

我的活动有xml

<?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="ameyo.genie.activity.HomeActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="50dp">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>



        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"
            app:theme="@style/Toolbar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bars"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
           />
            <ameyo.genie.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="@color/colorPrimary"
                />

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



    <android.support.design.widget.FloatingActionButton
        android:id="@+id/home_fab_dial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_dialpad_white"
        app:layout_anchor="@id/pager"
        app:layout_anchorGravity="bottom|center" />


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

和我的片段

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    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:background="@color/white">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recentcall_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

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

我在滑动列表视图时使工具栏滑动时出错了,或者在不使用任何第三个库的情况下有另一种方法。

2 个答案:

答案 0 :(得分:1)

试试这个:

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"
            app:theme="@style/Toolbar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bars"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
           />
            <ameyo.genie.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="@color/colorPrimary"
                />
 <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="50dp">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>

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

当您放置组件时,按位置排序,如果没有空格,每个组件都将超过先例!

答案 1 :(得分:0)

感谢Daniel Nugent,我忘了写android:layout_below="@+id/sliding_tabs&#34;在viewpager里面也删除了framelayout和height必须是wrapcontent现在我的最终代码是这个正在工作

<?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="ameyo.genie.activity.HomeActivity">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="6dp">
        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bars"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"
            app:theme="@style/Toolbar"
            app:elevation="0dp"
            app:layout_scrollFlags="scroll|enterAlways"
            />

        <ameyo.genie.SlidingTabLayout
            android:id="@+id/sliding_tabs"
            android:layout_below="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="?attr/colorPrimary"
            app:elevation="0dp"
            android:minHeight="?attr/actionBarSize"
            />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_below="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/home_fab_dial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_dialpad_white"
        app:layout_anchor="@id/pager"
        app:layout_anchorGravity="bottom|center" />


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