当前位置:网站首页>imageswitcher的功能和用法
imageswitcher的功能和用法
2022-07-07 15:40:00 【XLMN】
imageswitcher的功能和用法
public class MainActivity extends Activity {
int[] imageIds = new int[] { R.drawable.love, R.drawable.mia,
R.drawable.love, R.drawable.mia, R.drawable.love, R.drawable.mia,
R.drawable.love, R.drawable.mia, R.drawable.love, R.drawable.mia,
R.drawable.love, R.drawable.mia, R.drawable.love, R.drawable.mia,
R.drawable.love,R.drawable.love};
ImageSwitcher is;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.imageswitcher);
// 创建list对象,list对象的元素是map
List<Map<String, Object>> listitems = new ArrayList<Map<String, Object>>();
for (int i = 0; i < imageIds.length; i++) {
Map<String, Object> listItem = new HashMap<String, Object>();
listItem.put("image", imageIds[i]);
listitems.add(listItem);
}
// 获取显示图片的imageswitcher
is = (ImageSwitcher) findViewById(R.id.imageswitcher);
// 获取显示图片imageswitcher设置图片切换的动画效果。
is.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
// TODO Auto-generated method stub
// 创建imageview对象
ImageView iv = new ImageView(MainActivity.this);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new ImageSwitcher.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
// 返回imageview对象
return iv;
}
});
// 创建一个simpleAdapter
SimpleAdapter sa = new SimpleAdapter(this, listitems, R.layout.cell,
new String[] { "image" }, new int[] { R.id.imge1 });
GridView grid = (GridView) findViewById(R.id.gridview);
// 为gridview设置adapter
grid.setAdapter(sa);
// 添加列表项被选中的监听器
grid.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
is.setImageResource(imageIds[arg2]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
// 添加列表项被选中的监听器
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// 显示被单击的图片
is.setImageResource(imageIds[arg2]);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?><!-- 定义girdview组件 -->
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="4"
android:verticalSpacing="2dp" >
</GridView>
<!-- 定义一个imageswitcher组件 -->
<ImageSwitcher
android:id="@+id/imageswitcher"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out" >
</ImageSwitcher>
<?xml version="1.0" encoding="utf-8"?> <ImageView
android:id="@+id/imge1"
android:layout_width="match_parent"
android:layout_height="100dp"/>
边栏推荐
- Shallow understanding Net core routing
- 【TPM2.0原理及应用指南】 5、7、8章
- LeetCode 648(C#)
- [fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
- 麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
- 【可信计算】第十次课:TPM密码资源管理(二)
- What is cloud computing?
- How to add aplayer music player in blog
- 【网络攻防原理与技术】第1章:绪论
- 麒麟信安云平台全新升级!
猜你喜欢
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
【可信计算】第十二次课:TPM授权与会话
Devops' operational and commercial benefits Guide
【网络攻防原理与技术】第1章:绪论
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
命令模式 - Unity
【TPM2.0原理及应用指南】 16、17、18章
NeRF:DeepFake的最终替代者?
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
随机推荐
使用popupwindow創建对话框风格的窗口
[source code interpretation] | source code interpretation of livelistenerbus
From Devops to mlops: how do it tools evolve to AI tools?
Sator推出Web3游戏“Satorspace” ,并上线Huobi
Solidity函数学习
如何在软件研发阶段落地安全实践
Sator launched Web3 game "satorspace" and launched hoobi
MySQL usage notes 1
What is cloud computing?
Blue Bridge Cup final XOR conversion 100 points
Matplotlib绘图界面设置
L1-025 正整数A+B(Lua)
A tour of grpc:03 - proto serialization / deserialization
NeRF:DeepFake的最终替代者?
Solid function learning
策略模式 - Unity
第2章搭建CRM项目开发环境(搭建开发环境)
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
【饭谈】如何设计好一款测试平台?
LeetCode 535(C#)