【问题标题】:RecyclerView is below toolbarRecyclerView 在工具栏下方
【发布时间】:2016-06-07 10:37:25
【问题描述】:

问题:我在CoordinatorLayout 中有一个RecyclerView 和一个ToolbarRecyclerView 低于 Toolbar 但不应该。

问题:如何实现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>

ma​​schine_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>

【问题讨论】:

  • 将 margin top 属性应用到 recyclerview 。 android:layout_marginTop="20dp"
  • app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到您的FrameLayout

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


【解决方案1】:

只需将以下行添加到您的父布局,即Linearlayout of 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"

它会为你工作! :)

【讨论】:

    【解决方案2】:

    将您的代码更改为:

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

    【讨论】:

    • 如果您在主布局中使用 FrameLayout 作为容器,并且有一个单独的布局,其中包括 RecyclerView - 在这种情况下,您应该在 FrameLayout 中添加“app:layout_behavior=...”主布局!
    【解决方案3】:

    尝试将以下行添加到线性布局的android:layout_height="match_parent"下面的`maschine_fragment.xmlm

    android:paddingTop="?attr/actionBarSize"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2018-03-03
      相关资源
      最近更新 更多