PageTransformer在Android中禁用了滚动

时间:2019-04-01 07:50:09

标签: android android-fragments android-viewpager

我已经成功创建了这个FragmentManager的viewPager。现在我想在viewpager中添加自定义FadOut动画。这是代码

public class FadeOutTransformation implements ViewPager.PageTransformer {
@Override
public void transformPage(View page, float position) {

    page.setTranslationX(-position*page.getWidth());

    page.setAlpha(1-Math.abs(position));

}

}

我这样叫这种方法

    SPStoryFullAdapter adapter = new StoryFullAdapter(storyContents, this, getSupportFragmentManager());
    pager.setAdapter(adapter);
    pager = findViewById(R.id.viewPager);

    pager.setPageTransformer(true,new FadeOutTransformation());

    pager.post(() -> pager.setCurrentItem(needIncrementContentsSize ? 1 : 0));

添加此fadeOut动画时,无法滚动片段的内容

这是我的片段内容xml代码

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dimen_p_321"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:expandedTitleGravity="bottom|center"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:titleEnabled="false">



        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />



        <ImageView
            android:id="@+id/background_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:visibility="gone"

            app:layout_collapseMode="parallax" />


        <LinearLayout
            android:id="@+id/gradient_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dimen_p_321"
            android:background="@drawable/story_gradient_bottom_to_top"
            android:orientation="vertical" />


        <RelativeLayout
            android:id="@+id/alpha_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0"
            android:background="#000000" />


        <TextView
            android:id="@+id/story_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="@dimen/dimen_p_30"
            android:layout_marginRight="@dimen/dimen_p_30"
            android:layout_marginBottom="@dimen/dimen_p_20"
            android:fontFamily="@font/myriad_geo_mtavruli_bold"
            android:textColor="@android:color/white"
            android:textSize="@dimen/dimen_p_24" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dimen_p_30"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


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

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dimen_p_30">


                    <TextView
                        android:id="@+id/category_name"
                        android:layout_width="wrap_content"
                        android:layout_height="@dimen/dimen_p_30"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="@dimen/dimen_p_15"
                        android:gravity="center"
                        android:paddingTop="@dimen/dimen_p_5"
                        android:paddingBottom="@dimen/dimen_p_5"
                        android:paddingRight="@dimen/dimen_p_8"
                        android:paddingLeft="@dimen/dimen_p_8"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/dimen_p_12" />

                    <ImageView
                        android:id="@+id/category_close"
                        android:layout_width="@dimen/dimen_p_30"
                        android:layout_height="@dimen/dimen_p_30"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="@dimen/dimen_p_15"
                        android:background="@mipmap/story_category_close" />
                </RelativeLayout>


                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="@dimen/dimen_p_8"
                    android:layout_marginBottom="@dimen/dimen_p_15"
                    android:fontFamily="@font/myriad_geo_mtavruli_bold"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/dimen_p_14" />

            </LinearLayout>


        </android.support.v7.widget.Toolbar>

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

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


<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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


        <TextView
            android:id="@+id/story_title_video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="@dimen/dimen_p_30"
            android:layout_marginRight="@dimen/dimen_p_30"
            android:layout_marginTop="@dimen/dimen_p_20"
            android:fontFamily="@font/myriad_geo_mtavruli_bold"
            android:textColor="@android:color/black"
            android:visibility="gone"
            android:textSize="@dimen/dimen_p_24" />

        <TextView
            android:id="@+id/body_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dimen_p_30"
            android:paddingTop="@dimen/dimen_p_20"
            android:layout_marginRight="@dimen/dimen_p_30"
            android:paddingBottom="@dimen/dimen_p_90"
            android:fontFamily="@font/myriad_geo_regular"
            android:textSize="@dimen/dimen_p_14" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>


<Button
    android:id="@+id/action_view"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/dimen_p_47"
    android:layout_gravity="bottom|center"
    android:layout_marginBottom="@dimen/dimen_p_15"
    android:fontFamily="@font/myriad_geo_mtavruli_bold"
    android:paddingLeft="@dimen/dimen_p_40"
    android:paddingTop="@dimen/dimen_p_14"
    android:paddingRight="@dimen/dimen_p_40"
    android:paddingBottom="@dimen/dimen_p_14"
    android:layout_marginTop="@dimen/dimen_p_20"
    android:textColor="@android:color/white"
    android:textSize="@dimen/dimen_p_14" />

正如我所说的,一切工作都非常完美,但是在添加了这个fadeOut动画之后,我无法使用nestedScrollview滚动片段视图。 有什么办法可以解决这个问题?

0 个答案:

没有答案