如何在1图像淡入淡出第二形象吗? [英] how to fade in 1 image fade out 2nd image?
本文介绍了如何在1图像淡入淡出第二形象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现这个教程 HTTP: //android-er.blogspot.com/2012/02/animate-fade-infade-out-by-changing.html 淡出相同的图像如何改变这种code使用两个图像而褪色淡入1图像自动淡出第二???
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.animation.Animation;
进口android.view.animation.AnimationUtils;
进口android.widget.Button;
进口android.widget.ImageView;
公共类AndroidAnimTranslateActivity延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
按钮buttonFadeOut =(按钮)findViewById(R.id.fadeout);
最终ImageView的形象=(ImageView的)findViewById(R.id.image);
动画animationFadeIn = AnimationUtils.loadAnimation(这一点,R.anim.fadein);
image.startAnimation(animationFadeIn);
animationFadeIn.setAnimationListener(新AnimationListener(){
@覆盖
公共无效onAnimationStart(动画动画){
// TODO自动生成方法存根
}
@覆盖
公共无效onAnimationRepeat(动画动画){
// TODO自动生成方法存根
}
@覆盖
公共无效onAnimationEnd(动画动画){
// TODO自动生成方法存根
image.startAnimation(animationFadeOut);
}
});
最终的动画animationFadeOut = AnimationUtils.loadAnimation(这一点,
R.anim.fadeout);
buttonFadeOut.setOnClickListener(新Button.OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
// TODO自动生成方法存根
image.startAnimation(animationFadeOut);
}});
}
}
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/你好/>
<按钮
机器人:ID =@ + ID /淡入
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=淡入/>
<按钮
机器人:ID =@ + ID /淡出
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=淡出/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:重力=中心>
< ImageView的
机器人:ID =@ + ID /图像
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:SRC =@可绘制/ ic_launcher/>
< / LinearLayout中>
< / LinearLayout中>
< ------- fadein.xml - >!>
< XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:插=@机器人:动画/ linear_interpolator>
<阿尔法
机器人:fromAlpha =0.1
机器人:toAlpha =1.0
机器人:时间=2000
/>
< /集>
<!-------- fadeout.xml ----->
< XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:插=@机器人:动画/ linear_interpolator>
<阿尔法
机器人:fromAlpha =1.0
机器人:toAlpha =0.1
机器人:时间=2000
/>
< /集>
解决方案
我认为你应该使用Animationlistener:
image.startAnimation(animationFadeIn);
animationFadeIn.setAnimationListener(新AnimationListener(){
@覆盖
公共无效onAnimationStart(动画动画){
// TODO自动生成方法存根
}
@覆盖
公共无效onAnimationRepeat(动画动画){
// TODO自动生成方法存根
}
@覆盖
公共无效onAnimationEnd(动画动画){
// TODO自动生成方法存根
image.startAnimation(animationFadeOut);
}
});
所以,第二个动画将被启动,而第一个将结束
i found this tutorial http://android-er.blogspot.com/2012/02/animate-fade-infade-out-by-changing.html which fade in fade out same image how do change this code to use two images fade in 1 image fade out 2nd automatically???
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class AndroidAnimTranslateActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonFadeOut = (Button)findViewById(R.id.fadeout);
final ImageView image = (ImageView)findViewById(R.id.image);
Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
image.startAnimation(animationFadeIn);
animationFadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeOut);
}
});
final Animation animationFadeOut = AnimationUtils.loadAnimation(this,
R.anim.fadeout);
buttonFadeOut.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeOut);
}});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/fadein"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fade In"/>
<Button
android:id="@+id/fadeout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fade Out"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<!-------fadein.xml-->>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
<!--------fadeout.xml----->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
/>
</set>
解决方案
I think you should use Animationlistener:
image.startAnimation(animationFadeIn);
animationFadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeOut);
}
});
So second animation will be started while first will end
这篇关于如何在1图像淡入淡出第二形象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文