在我的布局中,我在屏幕顶部有一个按钮和一个AddView(下面的图片更好地解释了它)。我需要AddView仅在加载时显示,为此我创建了一个AdListener。但是现在我希望在显示AddView时我的按钮向下滑动。我怎么做?提前谢谢。
这是我的AdListener
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded(){
adView.bringToFront();
adView.startAnimation(slide_from_top);
}
});
这是我的XML动画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"/>
编辑
这是我的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>
答案 0 :(得分:0)
您可以控制动画开始/重复/结束时发生的事情。因此,您可以启动AdView动画,然后在onAnimationEnd
中,您可以将按钮转到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) {
}
});
编辑:看到您希望按钮向下滑动但仍然在视野中。你可以用同样的方式实现它。只需按钮的动画开始。