Tôi có một Hoạt động với hai tab. Mỗi tab chứa một đoạn với một số SwipeRefreshLayout
và RecyclerView
bên trong chúng.Ẩn Thanh công cụ với CoordinatorLayout, nhưng RecyclerView trên một đoạn
Trong Hoạt động, tôi có một CoordinatorLayout
với một AppBarLayout
(với một Toolbar
và TabLayout
) và một ViewPager
cho mảnh vỡ.
Bây giờ, những gì tôi muốn đạt được là: khi người dùng cuộn trong mảnh vỡ, Thanh công cụ, và không phải là các tab, da, giống như trong Cửa hàng Play.
Trong các ví dụ mà tôi đã đọc qua Internet, cách bố trí rất đơn giản: họ có RecyclerView
và Toolbar
bên trong CoordinatorLayout
trên xml tương tự.
Sau đó, họ chỉ cần viết:
<android.support.v7.widget.RecyclerView
android:id="@+id/rvToDoList"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
Và
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
Vì vậy, tôi không thể tìm ra cách để làm điều đó.
của xml của tôi như sau:
Các Layout hoạt động là:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/activity_main_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/color_text_primary"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/activity_main_tabs_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="@+id/activity_main_nav_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/color_primary"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="5dp"
android:overScrollMode="never"
android:smoothScrollbar="true" />
</android.support.v4.widget.DrawerLayout>
Và các mảnh vỡ là:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_coupons_swipe_refresh_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.yasevich.endlessrecyclerview.EndlessRecyclerView
android:id="@+id/fragment_coupons_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
Cảm ơn trước.
Tháo 'LinearLayout's – tachyonflux
Và' ứng dụng: layout_behavior = "@ string/appbar_scrolling_view_behavior" 'mục' ViewPager', không phải là 'SwipeRefreshLayout' – tachyonflux
Nope –