1

In my layout I have one button and an AddView on the top of the screen (Image below explain it better). I need the AddView to show only when it is loaded and for that I made an AdListener. But now I want my button to slide down when the AddView is shown. ¿How do I do that? Thank you in advance.

Here is my AdListener

adView.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded(){
            adView.bringToFront();
            adView.startAnimation(slide_from_top);
        }

    });

Here is my XML animation slide_from_top:

<?xml version="1.0" encoding="utf-8"?>
<translate
   xmlns:android="http://schemas.android.com/apk/res/android" 
   android:fromYDelta="-100%p"
   android:toYDelta="0%p"
   android:duration="1000"/>

EDIT

Here is my Layouts XML:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<com.google.android.gms.ads.AdView 
   xmlns:ads="http://schemas.android.com/apk/res-auto"
   android:id="@+id/adView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   ads:adUnitId="MY_AD_UNIT_ID"
   ads:adSize="BANNER"
   android:layout_alignParentTop="true"
   android:layout_centerHorizontal="true"/>   

<Button
   android:id="@+id/MY_BUTTON"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentTop="true"
   android:layout_centerHorizontal="true"
   android:text="MY_BUTTON" />
  </RelativeLayout>

enter image description here

stanete
  • 4,062
  • 9
  • 21
  • 30

1 Answers1

0

You can control what happens when an animation starts/repeats/ends. So you can start the AdView animation then in the onAnimationEnd you can have the button go to View.GONE

animation.setAnimationListener(new Animation.AnimationListener() {

@Override
public void onAnimationStart(Animation arg0) {

}           
@Override
public void onAnimationRepeat(Animation arg0) {

}           
@Override
public void onAnimationEnd(Animation arg0) {

}
});

Edit: Just saw that you want the button to slide down rather but still be in view. You can achieve it the same way. Just have button's animation start.

RED_
  • 2,997
  • 4
  • 40
  • 59
  • OK, but how can I make that Button slide and stop below the AdView? – stanete Feb 24 '14 at 12:00
  • You need the correct animation in res/anim. That will determine what the animation does. There is plenty of code out there for that. You then apply that to the button. You can set where the animation should start for the button, and where it will end. So it will end below the AdView. In the animation XML you can also set where the animation starts and ends in terms of position. – RED_ Feb 24 '14 at 12:24