ViewPager中的同步AppBarLayout偏移量

时间:2019-04-04 01:15:02

标签: android android-viewpager android-coordinatorlayout android-appbarlayout

父片段XML:


 const getToken = () => {
    Promise.all([
      SecureStore.getItemAsync('shifterEmail'),
      SecureStore.getItemAsync('shifterToken')  
    ])
   .then((response) => {
      const [email, token] = response
       return {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
          'Authorization': 'Token' +
          ' token=' + token + 
          ', email=' + email
        };
      }
    ).catch((error) => {
      console.error(error);
      throw error;
    });
 }

孩子将XML片段化:

 <androidx.coordinatorlayout.widget.CoordinatorLayout 
    ....
      <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

所以这是一个ViewPager,每个片段都有一个随内容滚动的AppBarLayout。但是,我要实现的是使所有片段中的所有AppBarLayout具有相同的偏移量。

但是,没有直接的方法可以更改AppBarLayout的偏移量。 <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/root_view" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.appbar.AppBarLayout android:id="@id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="-10dp" android:layout_marginRight="-10dp" android:background="@color/transparent" app:layout_scrollFlags="scroll"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="140dp" app:layout_collapseMode="parallax" app:layout_scrollFlags="scroll"> </androidx.constraintlayout.widget.ConstraintLayout> <include layout="@layout/tablayout" /> </com.google.android.material.appbar.AppBarLayout> <androidx.viewpager.widget.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/backgroundEmpty" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> 不能解决问题。我还尝试了offsetTopAndBottom,但该方法也不起作用。

0 个答案:

没有答案