[英]Animate two Views together in Android
在我的布局中,我在屏幕顶部有一个按钮和一个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"/>
编辑
这是我的布局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>
您可以控制动画开始/重复/结束时发生的情况。 因此,您可以启动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) {
}
});
编辑:只是看到您希望按钮向下滑动,但仍在视图中。 您可以用相同的方法来实现。 只需启动按钮的动画即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.