使用滑动刷新布局的片段不转换

问题描述 投票:0回答:1

我有一个包含一个包含Recycler视图的刷卡刷新布局的片段,我添加了自定义转换,并在我开始片段的事务之前通过frag.setEnterTransition()将其与片段相关联。但是它根本没有转变。它突然出现,就像它没有过渡一样。

为了缩小我可能出错的地方,我用LinearLayout而不是swipeRefreshLayout重新编写它,并且片段按预期转换。

这是片段的xml。

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout_inapp_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/rv_inapp_messages_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:padding="@dimen/transactions_space_small"/>

        <include layout="@layout/widget_empty_screen"/>
    </FrameLayout>

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

这就是片段的交易方式。

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    fragment.setEnterTransition(bottomGravitySlide);
    fragment.setExitTransition(fadeOut);
    fragment.setAllowEnterTransitionOverlap(false);
    fragment.setAllowReturnTransitionOverlap(false);
}
fragmentTransaction.replace(R.id.vg_full_container, fragment, TAG_INTRODUCTION).commitAllowingStateLoss();

我正在使用API​​23,因此API检查应该不是问题。

我哪里错了?如果我想拥有swipeRefreshLayout并且仍然能够转换,我该怎么办?

android android-fragments android-5.0-lollipop swiperefreshlayout android-transitions
1个回答
0
投票

我想以编程方式通过SwipeRefreshLayout内的转换将浮动操作按钮移动到顶部中心,并遇到相同的问题。

通过FrameLayout封装SwipeRefreshLayout解决了我的问题。

之前:

<android.support.v4.widget.SwipeRefreshLayout
   android:id="@+id/swipe_container"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       <!-- some other views -->
       <android.support.design.widget.FloatingActionButton
           android:id="@+id/floating_action_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="end|bottom"
          android:src="@drawable/add"
          android:tint="@android:color/white"
          android:layout_margin="@dimen/pad16dp" />
      </RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>

后:

<FrameLayout
    android:id="@+id/transitions_container"
    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.support.v4.widget.SwipeRefreshLayout
       android:id="@+id/swipe_container"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- some other views -->
        </RelativeLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floating_action_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:src="@drawable/add"
        android:tint="@android:color/white"
        android:layout_margin="@dimen/pad16dp" />
</FrameLayout>
© www.soinside.com 2019 - 2024. All rights reserved.