0

I've got a layout like that

<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"
android:animateLayoutChanges="true">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:id="@+id/relativeLayout">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/category_1_full"
        android:scaleType="centerCrop"
        android:id="@+id/categoryImageView" />
(...)
</RelativeLayout>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/relativeLayout"
    >
    <GridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gridView"
        android:numColumns="2"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

and then I do animate the first relative layout like that

float _height = 120.05f;
ObjectAnimator a1 = ObjectAnimator.ofFloat(relativeLayout, "translationY", -_height);
ObjectAnimator a2 = ObjectAnimator.ofFloat(swipeRefreshLayout, "translationY", -_height);
a2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
    @Override
    public void onAnimationUpdate(ValueAnimator animation)
    {
        swipeRefreshLayout.invalidate();
        gridView.invalidate();
    }
});
AnimatorSet animation = new AnimatorSet();
animation.play(a1).with(a2);
animation.start();

As you can see I tried to invalidate concerned views into an updateListener but it doesn't work.

I thought the refresh/gridViews will update automatically because of the relation on the layout (match_parent and alignXX) but it is not the case. How should I do?

jrmgx
  • 719
  • 8
  • 24
  • can you explain in detail, what are you trying to do. Unable to understand from your question. – Murtaza Khursheed Hussain Feb 02 '15 at 13:54
  • I'm animating `@+id/relativeLayout` about 120 px to the top, so I wanted the SwipeRefreshLayout to follow that animation (because the rules on the XML specify `android:layout_below="@+id/relativeLayout"`) but it is not the case. Of course I could do the animation on the swipe layout too but then it won't keep the `android:layout_alignParentBottom="true"` rule ... – jrmgx Feb 02 '15 at 14:05
  • Another way to see it is : how I animate the swipe height (not scale) so it will keep under relativelayout and on parent bottom – jrmgx Feb 02 '15 at 14:06
  • set `fillAfter="true"` to your `@+id/relativeLayout` in animation. Do not animate swipe layout. – Murtaza Khursheed Hussain Feb 02 '15 at 14:08
  • As you can see, i'm using code and not xml, so i'm not sure where to put that? Beside, the doc is unclear about that feature, but as i understand, it doesn't seem to be related. I'll try my best in this direction just in case :) – jrmgx Feb 02 '15 at 19:45
  • What u do in xml can be done through code too – Murtaza Khursheed Hussain Feb 03 '15 at 03:31
  • What do you mean "It doesn't work" what is the problem? what happens? You shouldn't invalidate from outside the class. That's not the responsibility of any object but the view itself. When you change a property that requires a redraw the class will invalidate() itself. – Andrew G Feb 06 '15 at 07:45

1 Answers1

0

This answer will give you a lot of information. https://stackoverflow.com/a/20274698/3841420

It relates to pushing a view off of the screen but you can just modify width (or scaleX) instead of translation of the Fragment that you are keeping on the screen.

Community
  • 1
  • 1
Andrew G
  • 2,596
  • 2
  • 19
  • 26