RecyclerView位于工具栏下方

时间:2016-06-07 10:37:26

标签: android xml android-recyclerview toolbar android-coordinatorlayout

问题:我在RecyclerView中有ToolbarCoordinatorLayoutRecyclerView低于Toolbar,但不应该。{/ p>

enter image description here

问题:如何实现RecyclerViewToolbar有一个边框?

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

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

    <include
        android:id="@+id/toolbar_main"
        layout="@layout/toolbar"></include>

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

    <FrameLayout
        android:id="@+id/maschinelistcontainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

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

maschine_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:scrollbars="vertical" />

</LinearLayout>

2 个答案:

答案 0 :(得分:8)

只需在父级布局中添加以下行,即Linearlayout

maschine_fragment.xml
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

或者将此行添加到activity_main.xml

的Framelayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"

它适合你! :)

答案 1 :(得分:3)

将您的代码更改为:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

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

    <include
        android:id="@+id/toolbar_main"
        layout="@layout/toolbar"></include>

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

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

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