我试图克隆Google Playstore用户界面。 所以,我有一个NavigationView,CoordinatorLayout - > AppBarLayout - >工具栏,TabLayout,ViewPager。选项卡的布局在1个垂直RecyclerView中有n个水平RecyclerView。
我的问题:
我的布局文件:
activity_navigation_drawer.xml: 主要活动布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/layout_main_content_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/header_navigation_drawer"
app:menu="@menu/menu_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
layout_main_content_nav_drawer.xml: 包含在上面的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.aishwarya.materialdesign1.NavigationDrawerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/layout_content_nav_drawer"/>
</android.support.design.widget.CoordinatorLayout>
layout_content_nav_drawer.xml: 包含在上面的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.aishwarya.materialdesign1.NavigationDrawerActivity"
tools:showIn="@layout/layout_main_content_nav_drawer">
<FrameLayout
android:id="@+id/fl_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
fragment_home_screen.xml: 包含TabLayout&amp;的片段ViewPager。我从我的主要活动中打开它来显示内容。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tl_sliding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/color_primary"
app:tabTextColor="@android:color/black"
app:tabIndicatorColor="@color/color_primary"
app:tabIndicatorHeight="2dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
答案 0 :(得分:0)
您可以轻松拨打电话
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);