工具栏重叠Recyclerview

时间:2018-05-17 13:30:50

标签: java android

我正在开发一个应用程序,其中我使用了recyclerview以及工具栏,我的惊喜工具栏重叠了recyclerview,即使我使用了协调器布局,也许我在正确实现它时出错了所以这就是。< / p>

XML

 <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"
        >

    <!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
    <!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <!-- Toolbar is the actual app bar with text and the action items -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:titleTextColor="@color/White"
            app:layout_scrollFlags="scroll|enterAlways|snap">
            <com.ct.listrtrial.Custom.CustomTextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Pulse"
                android:textColor="@color/White"
                android:textSize="30sp"/>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            tools:context="com.ct.listrtrial.fragments.FeedFragment">


            <android.support.v7.widget.RecyclerView
                android:id="@+id/feed_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="9"

                android:paddingTop="15dp">

            </android.support.v7.widget.RecyclerView>


        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="5dp"
        android:src="@drawable/ic_search_black_24dp" />
    </android.support.design.widget.CoordinatorLayout>

2 个答案:

答案 0 :(得分:0)

包含NestedScrollView的{​​{1}}个人应具有RecyclerView属性。

这会告知app:layout_behavior="@string/appbar_scrolling_view_behavior" CoordinatorLayout需要与应用栏协调一致。

答案 1 :(得分:0)

您需要在app:layout_behavior="@string/appbar_scrolling_view_behavior"

中添加android.support.v4.widget.NestedScrollView
<?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"
    >

<!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
<!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

    <!-- Toolbar is the actual app bar with text and the action items -->
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@color/White"
        app:layout_scrollFlags="scroll|enterAlways|snap">
        <com.ct.listrtrial.Custom.CustomTextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pulse"
            android:textColor="@color/White"
            android:textSize="30sp"/>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.ct.listrtrial.fragments.FeedFragment">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/feed_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="9"

            android:paddingTop="15dp">

        </android.support.v7.widget.RecyclerView>


    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="5dp"
    android:src="@drawable/ic_search_black_24dp" />
</android.support.design.widget.CoordinatorLayout>