android 图片淡入,Android使用ImageView淡入和淡出

要实现这一点,你已经开始,你将需要添加一个

AnimationListener,以便您可以检测动画的开始和结束。当调用淡出的onAnimationEnd()时,您可以将ImageView对象的可见性设置为View.INVISIBLE,切换图像并开始淡入动画 – 您还需要另一个AnimationListener。当你收到onAnimationEnd()为你的淡入动画,设置ImageView为View.VISIBLE,这应该给你的效果,你正在寻找。

我之前已经实现了类似的效果,但我使用了一个ViewSwitcher与2 ImageViews而不是一个单一的ImageView。你可以设置“in”和“out”动画的ViewSwitcher与您的淡入和淡出,以便它可以管理AnimationListener实现。然后你需要做的是在2个ImageView之间交替。

编辑:

为了更有用,这里是如何使用ViewSwitcher的一个快速示例。我在https://github.com/aldryd/imageswitcher包括了完整的源代码。

activity_main.xml

android:id="@+id/switcher"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:inAnimation="@anim/fade_in"

android:outAnimation="@anim/fade_out" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:scaleType="fitCenter"

android:src="@drawable/sunset" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:scaleType="fitCenter"

android:src="@drawable/clouds" />

MainActivity.java

// Let the ViewSwitcher do the animation listening for you

((ViewSwitcher) findViewById(R.id.switcher)).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

ViewSwitcher switcher = (ViewSwitcher) v;

if (switcher.getDisplayedChild() == 0) {

switcher.showNext();

} else {

switcher.showPrevious();

}

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值