0

I have a fragment with a swipe-refresh layout containing a Recycler view and I added custom transitions and associated it with the fragment through frag.setEnterTransition() before the I started the fragment's transaction. But however it doesn't transition at all. It just abruptly appears, just as it would without transitions.

To narrow-down where I could have gone wrong, I redid it with a LinearLayout instead of swipeRefreshLayout and the fragment transitions as expected.

This is my xml for the fragment.

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

This is how the fragment gets transacted.

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();

And I'm using API23, so the API check shouldn't be the problem.

Where am I going wrong? What should I do if I want to have swipeRefreshLayout and still be able to transition?

not_again_stackoverflow
  • 1,285
  • 1
  • 13
  • 27
  • What you mean by "just abruptly appears". Are you trying to programmatically show the pull animation which then starts the refresh animation? (just like the user himself did pull-to-refresh?) – Sufian Aug 04 '16 at 10:27
  • I mean that the fragment appears without transitioning into the screen as per the transition I defined, as in without any transitions. ( my custom transition makes the layout slide from bottom which isn't happening ). And no I am not programatically trying to show the pull animation. Only shows when the user refreshes. – not_again_stackoverflow Aug 04 '16 at 10:30
  • Update your question with the code where you're opening the fragment. – Sufian Aug 04 '16 at 10:46
  • Do any of the answers on this question help? http://stackoverflow.com/questions/27505403/android-lollipop-setentertransition-for-fragment-not-working-properly-on-exi – Sufian Aug 04 '16 at 11:23
  • @Sufian tried them out. Still not working out! – not_again_stackoverflow Aug 04 '16 at 11:39
  • I guess it is some bug. If you can create a sample app with both scenarios (one with `LinearLayout` where the animation works, and the other with `SwipeRefreshLayout` where it doesn't), it would help Google to fix it. Create [an issue here](https://code.google.com/p/android/issues/list) and post a link (to the created issue) as a comment under this question. – Sufian Aug 05 '16 at 10:54

1 Answers1

0

I wanted to programmatically move a floating action button to the top center by a transition within a SwipeRefreshLayout and encountered the same problem.

Encapsulating the SwipeRefreshLayout by a FrameLayout solved my issue.

Before:

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

After:

<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>
memres
  • 439
  • 2
  • 9