单击其他选项卡时,可滚动标签栏无法恢复

时间:2016-09-05 15:32:55

标签: android scroll tabs

问题2: 单击另一个选项卡时,选项卡栏无法还原到原始位置(选项卡1带有非回收查看)。它粘在顶部,直到它可以使用将它发送到顶部的标签2向后滚动

我使用的是可重复使用的代码,无需每次都重写App Bar和Navigation Drawer。

问题1详细信息: 当滚动回收者视图时,应用栏可以滚动,但是标签栏隐藏在应用栏后面,直到应用栏向上滚出屏幕(标签栏无法移动并保持在0 y坐标)

问题1(已修复): 解决方案:移动线" app:layout_behavior =" @ string / appbar_scrolling_view_behavior"从viewpager到framelayout

Motion 1 motion 2 ←截屏 我的代码是:

activity_base.xml(将所有页面放入FrameLayout的活动)

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

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <!--Toolbar-->
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <!--Activity container to put page content-->
    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</android.support.design.widget.CoordinatorLayout>

<!--
NavigationView - place inside drawer
-->
<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/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    />

pg02_push.xml(包含少量标签的页面)

<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=".Pg02Push">
<!--
AppBarLayout > Toolbar, TabLayout
-->
<android.support.design.widget.AppBarLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:layout_below="@+id/toolbar"
    >

    <!--TabLayout-->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabGravity="fill"/>

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

<!--VIewPager for Tab-->
<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />

pg02tab02_allpush.xml(带回收者视图的标签)

<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.fcm.firsthandpptynoti.Pg02Tab02AllPush">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview_tab02_allpush"

    android:divider="#FFB900"

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

BaseActivity.java

    @Override
public void setContentView(@LayoutRes int layoutResID){
    /**
     * This is going to be our actual root layout.
     * Instantiates a layout XML file into its corresponding View objects.
     * It is never used directly. Instead, use getLayoutInflater() or
     * getSystemService(Class) to retrieve a standard LayoutInflater instance
     * that is already hooked up to the current context and correctly configured for the device you are running on
     * android.view.LayoutInflater#inflate(int, android.view.ViewGroup)
     */
    mDrawerLayoutFull = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
    /**
     * {@link FrameLayout} to inflate the child's view. We could also use a {@link android.view.ViewStub}
     *
     */
    FrameLayout activityContainer = (FrameLayout) mDrawerLayoutFull.findViewById(R.id.flContent);
    getLayoutInflater().inflate(layoutResID, activityContainer, true);
    /**
     * Note that we don't pass the child's layoutId to the parent,
     * instead we pass it our inflated layout.
     */
    super.setContentView(mDrawerLayoutFull);

    /*
    Toolbar
    Set a Toolbar to replace the ActionBar.
    Initializing Toolbar and setting it as the actionbar
    */
    mToolbar = (Toolbar) findViewById(R.id.toolbar);


    if (useToolbar()) {
        mToolbar.setTitle(setTitleOnToolbar());
        setSupportActionBar(mToolbar);
    }
    else {
        mToolbar.setVisibility(View.GONE);
    }
    /*
    Navigation View
    */
    //
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);

    //Navigation View
    setUpNavigationView();
    //....
    //...
    //..
    //.
}
//End of setContentView

Pg02Push.java

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pg02_push);

    /*
    Tab
    */
    //ViewPager - Layout manager that allows the user to flip left and right through pages of data.
    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    //MyViewPagerAdapter
    setupViewPager(mViewPager);
    //...
    //..
    //.

    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    //Assigns the ViewPager to TabLayout
    //The one-stop shop for setting up this TabLayout with a ViewPager.
    mTabLayout.setupWithViewPager(mViewPager);

} // End of onCreate

0 个答案:

没有答案
相关问题