0

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

Keerthiraj
  • 23
  • 5
  • check This http://stackoverflow.com/questions/20374823/android-animate-my-relative-layout-from-bottom-to-top-and-top-to-bottom-using-tr – Farhan Shah Dec 06 '13 at 07:07

2 Answers2

1

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.

Mohit Verma
  • 3,025
  • 1
  • 20
  • 36
0

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" />
Randroid
  • 3,688
  • 5
  • 30
  • 55
  • movement.setAnimationListener(this);...Iam getting the error for setAnimationListener.. Can u tell me what is this object – Keerthiraj Aug 16 '11 at 07:01
  • 1
    Your activity should implement AnimationListner – Randroid Aug 16 '11 at 07:04
  • But when I do that it asks me to add unimplemented methods.. after adding those methods should I edit those methods.. – Keerthiraj Aug 16 '11 at 07:14
  • not necessary to edit the methods, if it works correctly just accept the anwer thats it ,good luck :) – Randroid Aug 16 '11 at 07:21
  • Animation movement; RelativeLayout layout; layout = (RelativeLayout) findViewById(R.id.relativeLayout); movement=AnimationUtils.loadAnimation(this, R.layout.animation_test5); movement.reset(); movement.setFillAfter(true); movement.setAnimationListener(this); layout.startAnimation(movement); this is what I do.. and not getting the result.. – Keerthiraj Aug 16 '11 at 08:00
  • Hi, it works proper for me.. But the thing is that the screen slides down and disappear..where as I want the screen to slide down and remain visible there.. any help on this ? – Keerthiraj Aug 16 '11 at 08:11
  • use layout.setVisibility(true); see the edited code above it works – Randroid Aug 16 '11 at 08:38
  • and also in onendAnimation() method use setFillAfter(true); – Randroid Aug 16 '11 at 09:07
  • @Raghav : When I want to do down at that what I have to do changes mean after visible when click on button it disappear but with down to top effect ? – Nirav Ranpara Oct 25 '12 at 06:06