RecyclerView不会进入tabLayout和工具栏下

问题描述 投票:0回答:1

我使工具栏和TabLayout透明化。在TabLayout中,我有两个使用RecyclerView的片段。当我滚动时,recyclerView的内容不会在tolbar下面。请告诉我如何解决。我使用的行为,但它似乎无法正常工作

app_bar_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"
    tools:context=".activity.MainActivity"
    android:id="@+id/coordinator">

  <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="112dp"
      android:background="@color/transparent"  />

  <android.support.design.widget.AppBarLayout
      android:id="@+id/app_bar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/transparent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/transparent">

      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical">

        <TextView ..... />
        <TextView ..... />

      </LinearLayout>
    </android.support.v7.widget.Toolbar>
    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_width="match_parent">

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

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

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

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

fragment.xml之

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".fragment.PoemFragment">

   <android.support.v7.widget.RecyclerView
        android:id="@+id/rvPoem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:clipToPadding="false"
        android:paddingBottom="88dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</RelativeLayout>
android xml android-layout
1个回答
0
投票

您应该在该视图的根目录中使用此行为,该行为要放在AppBarLayout下面,而不是在视图子(Fragments)中

只需将此行为添加到ViewPager

只是改变 :

  <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="112dp"
      android:background="@color/transparent"  />

至 :

  <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="112dp"
      android:background="@color/transparent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" />
© www.soinside.com 2019 - 2024. All rights reserved.