How to animate scaling of relative layout (which contains many layouts and ImageViews inside)
I tried to scale, but when scaling the layouts internally they shrink, Can anyone explain how to animate the layout without compression
need to scale letterLayout from slightly above parent bottom level up
Animation anim = new ScaleAnimation(
1f, 1f, // Start and end values for the X axis scaling
startScale, endScale, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 1f); // Pivot point of Y scaling
anim.setFillAfter(false); // Needed to keep the result of the animation
anim.setDuration(1000);
v.startAnimation(anim);
Layout format
<RelativeLayout 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"
tools:context="com.sample.LaunchScreenActivity">
<ImageView
android:layout_marginTop="195dp"
android:layout_marginLeft="26dp"
android:src="@drawable/ic_envelope_back"
android:layout_width="308dp"
android:layout_height="327dp" />
<RelativeLayout
android:id="@+id/letterLayout"
android:layout_width="284dp"
android:layout_height="451dp"
android:layout_marginLeft="38dp"
android:layout_marginTop="19dp">
<RelativeLayout
android:id="@+id/logo_layout"
android:layout_width="284dp"
android:layout_height="236dp"
android:background="#ff33">
<ImageView
android:layout_centerInParent="true"
android:src="@drawable/ic_logo_launch_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:background="#ff3344"
android:layout_below="@id/logo_layout"
android:layout_width="284dp"
android:layout_height="215dp">
<Button
android:layout_width="160dp"
android:layout_height="41dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:background="#FC5D2D"
android:text="brinblox_login"
android:textColor="#ffff"/>
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:layout_marginTop="316dp"
android:layout_width="308dp"
android:layout_height="206dp"
android:layout_marginLeft="26dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_envelope_front"/>
</FrameLayout>
</RelativeLayout>
+3
source to share
1 answer
I would suggest you use a Value animator like this and change the RelativeLayout fields:
final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
ValueAnimator va = ValueAnimator.ofInt(initialMargin, finalMargin);
int mDuration = 3000; //in millis
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
params.setMargins((int)animation.getAnimatedValue(),(int)animation.getAnimatedValue(),(int)animation.getAnimatedValue(),(int)animation.getAnimatedValue());
relativeLayout.setLayoutParams(params);
}
}
);
va.start();
Hope it helps.
0
source to share