欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

android 图片跑马灯动画,ImageView 图片循环跑马灯的效果

发布时间:2024/7/23 编程问答 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 android 图片跑马灯动画,ImageView 图片循环跑马灯的效果 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

不解释了  直接上代码了

main.xml布局文件,记住必须用RelativeLayout将ImageView重叠

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" android:id="@+id/rl">

android:background="@drawable/icon" android:layout_below="@+id/rl"

android:layout_height="120dp" />

android:background="@drawable/expriment" android:layout_below="@+id/rl"

android:layout_height="120dp" />

android:layout_height="wrap_content"  android:layout_below="@id/imageView"/>

主类

public class IamgeTranslatActivity extends Activity {

/** Called when the activity is first created. */

public ImageView imageView;

public ImageView imageView2;

public Animation animation1;

public Animation animation2;

public TextView text;

public boolean juage = true;

public int images[] = new int[] { R.drawable.icon, R.drawable.expriment,

R.drawable.changer, R.drawable.dataline, R.drawable.preffitication };

public int count = 0;

public Handler handler = new Handler();

public Runnable runnable = new Runnable() {

@Override

public void run() {

// TODO Auto-generated method stub

AnimationSet animationSet1 = new AnimationSet(true);

AnimationSet animationSet2 = new AnimationSet(true);

imageView2.setVisibility(0);

TranslateAnimation ta = new TranslateAnimation(

Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,

-1f, Animation.RELATIVE_TO_SELF, 0f,

Animation.RELATIVE_TO_SELF, 0f);

ta.setDuration(2000);

animationSet1.addAnimation(ta);

animationSet1.setFillAfter(true);

ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f,

Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,

0f, Animation.RELATIVE_TO_SELF, 0f);

ta.setDuration(2000);

animationSet2.addAnimation(ta);

animationSet2.setFillAfter(true);

//iamgeView 出去  imageView2 进来

imageView.startAnimation(animationSet1);

imageView2.startAnimation(animationSet2);

imageView.setBackgroundResource(images[count % 5]);

count++;

imageView2.setBackgroundResource(images[count % 5]);

text.setText(String.valueOf(count));

if (juage)

handler.postDelayed(runnable, 6000);

Log.i("handler", "handler");

}

};

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

imageView = (ImageView) findViewById(R.id.imageView);

imageView2 = (ImageView) findViewById(R.id.imageView2);

text=(TextView)findViewById(R.id.text);

text.setText(String.valueOf(count));

//将iamgeView先隐藏,然后显示

imageView2.setVisibility(4);

handler.postDelayed(runnable, 2000);

}

public void onPause() {

juage = false;

super.onPause();

}

}

转载:http://www.adobex.com/android/source/details/00000419.htm

总结

以上是生活随笔为你收集整理的android 图片跑马灯动画,ImageView 图片循环跑马灯的效果的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。