Android之ImageSwitcher的实例详解
作者:lqh 时间:2022-06-08 06:03:14
Android之ImageSwitcher的实例详解
一. 简单示例
实例代码:
public class AndroidUIActivity extends Activity {
// 当前显示的图片索引
private int index;
// 图片数组
private int[] images = { R.drawable.image1, R.drawable.image2,
R.drawable.image3, R.drawable.image4, R.drawable.image5 };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 全屏设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
// 得到ImageSwitcher对象
final ImageSwitcher is = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
// 实现并设置工厂内部接口的makeView方法,用来显示视图。
is.setFactory(new ViewFactory() {
public View makeView() {
return new ImageView(AndroidUIActivity.this);
}
});
// 设置图片来源
is.setImageResource(images[index]);
// 设置点击 *
is.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 点击会切换图片
index++;
if (index >= images.length) {
index = 0;
}
is.setImageResource(images[index]);
}
});
// 设置切入动画
is.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(),
android.R.anim.slide_in_left));
// 设置切出动画
is.setOutAnimation(AnimationUtils.loadAnimation(
getApplicationContext(), android.R.anim.slide_out_right));
}
}
main.xml
<?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" >
<ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageSwitcher>
</LinearLayout>
二. 运行结果
启动
点击后切换过程
来源:http://blog.csdn.net/gjanyanlig/article/details/6943153
标签:Android,ImageSwitcher
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
学习Java的Date、Calendar日期操作
2023-09-04 22:26:38
SSH框架网上商城项目第22战之银行图标以及支付页面显示
2022-02-18 19:34:03
![](https://img.aspxhome.com/file/2023/5/89635_0s.png)
Unity3d实现Flappy Bird游戏
2023-09-17 20:54:29
![](https://img.aspxhome.com/file/2023/5/77295_0s.png)
SpringBoot如何读取war包jar包和Resource资源
2023-11-09 01:40:44
Java对象转json JsonFormat注解
2022-08-27 00:44:09
C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法
2021-06-06 04:59:48
AndroidStduio3.0 使用gradle将module打包jar文件的方法
2023-07-01 06:57:20
![](https://img.aspxhome.com/file/2023/4/84224_0s.png)
Android实现掷骰子效果
2022-06-16 01:09:16
![](https://img.aspxhome.com/file/2023/6/103926_0s.gif)
Easyui的combobox实现动态数据级联效果
2022-02-15 07:26:13
![](https://img.aspxhome.com/file/2023/0/91080_0s.jpg)
CDMA 猫用AT命令发中文短信(C#)
2021-07-22 08:19:46
Android开发之滑动数值选择器NumberPicker用法示例
2022-08-04 07:22:36
![](https://img.aspxhome.com/file/2023/6/126706_0s.gif)
C#如何安全、高效地玩转任何种类的内存之Span的本质
2022-10-23 10:59:15
![](https://img.aspxhome.com/file/2023/8/77298_0s.png)
用c#实现简易的计算器功能实例代码
2022-05-09 19:28:51
![](https://img.aspxhome.com/file/2023/5/113735_0s.png)
浅谈JVM之使用JFR解决内存泄露
2022-10-19 01:55:30
![](https://img.aspxhome.com/file/2023/3/81953_0s.jpg)
Java多线程的具体介绍与使用笔记小结
2023-01-17 05:23:13
![](https://img.aspxhome.com/file/2023/2/119162_0s.png)
深入委托与多播委托的详解
2023-05-29 07:07:15
Android系统设置中的清除数据会清除哪些数据?
2022-09-04 04:48:13
Java中Cookie和Session的那些事儿
2022-09-24 08:24:54
![](https://img.aspxhome.com/file/2023/7/78377_0s.png)
anroid开发教程之spinner下拉列表的使用示例
2023-10-05 05:42:22
详解SpringBoot统一响应体解决方案
2023-03-08 08:54:13