当前位置:网站首页>Functions and usage of imageswitch
Functions and usage of imageswitch
2022-07-07 17:36:00 【XLMN】
imageswitcher The function and usage of
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);
// establish list object ,list The element of the object is 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);
}
// Get the imageswitcher
is = (ImageSwitcher) findViewById(R.id.imageswitcher);
// Get display picture imageswitcher Set up the animation effect of picture switching .
is.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
// TODO Auto-generated method stub
// establish imageview object
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));
// return imageview object
return iv;
}
});
// Create a 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);
// by gridview Set up adapter
grid.setAdapter(sa);
// Add listener with list item selected
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
}
});
// Add listener with list item selected
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// Show clicked pictures
is.setImageResource(imageIds[arg2]);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?><!-- Definition girdview Components -->
<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>
<!-- Define a imageswitcher Components -->
<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"/>
边栏推荐
- PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
- 麒麟信安中标国网新一代调度项目!
- Sator launched Web3 game "satorspace" and launched hoobi
- 使用Stace排除故障的5种简单方法
- [video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
- 自定义View必备知识,Android研发岗必问30+道高级面试题
- [fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
- 【TPM2.0原理及应用指南】 16、17、18章
- 鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
猜你喜欢
随机推荐
Flask搭建api服务-SQL配置文件
What is cloud computing?
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
本周小贴士#134:make_unique与私有构造函数
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
第1章CRM核心业务介绍
MRS离线数据分析:通过Flink作业处理OBS数据
mysql使用笔记一
centos7安装mysql笔记
The top of slashdata developer tool is up to you!!!
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
责任链模式 - Unity
Flask搭建api服务-生成API文档
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
redis主从、哨兵主备切换搭建一步一步图解实现
阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
actionBar 导航栏学习
L1-025 正整数A+B(Lua)
【TPM2.0原理及应用指南】 12、13、14章