【问题标题】:fragment from viewPager hidding behind on tab of action barviewPager 的片段隐藏在操作栏的选项卡上
【发布时间】:2016-08-04 20:59:50
【问题描述】:

实际上我正在尝试构建一个 listView/recyclerView 。在滚动列表时,操作栏隐藏在操作栏是工具栏的位置,但列表视图的某些部分隐藏在选项卡后面。在这里,我使用了具有 app:layout_scrollFlags="scroll|enterAlways" 的 AppBarLayout 和工具栏,并且在我的 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>

我是否在使工具栏在滑动列表视图时滑动时做错了什么,或者有另一种方法可以在不使用任何第三个库的情况下做到这一点。

【问题讨论】:

标签: android android-layout listview android-fragments


【解决方案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>

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

【讨论】:

  • 执行此操作后,选项卡会隐藏,并且在滚动列表视图时,选项卡会显示在工具栏或操作栏上
  • 尝试颠倒SlidingTabLayout和Toolbar的顺序
  • 通过这样做,工具栏会被隐藏,操作栏上只有标签\
  • 抱歉,我没有看到您将 framelayout 放在 AppBarLayout 中。现在它没有隐藏并且工作正常,但现在的问题是列表没有滚动。
  • 添加滚动布局,或检查您是否禁用列表中的滚动。
【解决方案2】:

感谢 Daniel Nugent,我忘了在 viewpager 中写 android:layout_below="@+id/sliding_tabs" 并且还删除了 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2016-09-03
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    相关资源
    最近更新 更多