Keerthiraj
Keerthiraj

Reputation: 23

Animating the Layout

I have requirement for my project. I want the my Relative layout to slide from top to bottom ..Can anyone please give me some help on this

Thanks, Keerthi

Upvotes: 0

Views: 844

Answers (2)

Randroid
Randroid

Reputation: 3698

Its simple,

Create a layout and apply translate animation on the layout. In the XML make the layout invisible and in your code make it visible

Change this XML according to ur need

       <RelativeLayout
 android:id="@+id/linearLayout3"
 android:layout_width="wrap_content"
 android:layout_height="220dip"
 android:orientation="vertical"
 android:layout_marginTop="480dip"
>
</RelativeLayout>    

The java code is like this

         Animation movement5; 
  layout3 = (LinearLayout) findViewById(R.id.linearLayout3);


              layout3.setVisibility(true); USE THIS LINE //EDITED

 movement5 = AnimationUtils.loadAnimation(this,R.layout.animation_test5);
    movement5.reset();
        movement5.setfillafter(true);
    movement5.setAnimationListener(this);
         layout3.startAnimation(movement5);

animation_test5.xml .

       <?xml version="1.0" encoding="utf-8"?>
     <translate xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromXDelta="0%" android:toXDelta="0%" android:fromYDelta="-300%"
  android:toYDelta="100%" android:duration="3000" android:zAdjustment="normal" />

Upvotes: 0

Mohit Verma
Mohit Verma

Reputation: 3025

Use the class TranslateAnimation

public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

Here you can give values for fromYDelta and toYDelta for top to bottom animation. And call the methods setDuration(time in milliseconds) and setFillAfter(true) by the object of the class TranslateAnimation.

Upvotes: 1

Related Questions