当前位置:网站首页>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"/>
边栏推荐
- Flash build API Service - generate API documents
- The top of slashdata developer tool is up to you!!!
- The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
- 管理VDI的几个最佳实践
- 第2章搭建CRM项目开发环境(数据库设计)
- redis主从、哨兵主备切换搭建一步一步图解实现
- 【可信计算】第十二次课:TPM授权与会话
- [Fantan] how to design a test platform?
- textSwitch文本切换器的功能和用法
- 第3章业务功能开发(安全退出)
猜你喜欢
【信息安全法律法規】複習篇
Linux 安装mysql8.X超详细图文教程
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
textSwitch文本切换器的功能和用法
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
Leetcode brush questions day49
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
【信息安全法律法规】复习篇
mysql官网下载:Linux的mysql8.x版本(图文详解)
随机推荐
Solid function learning
The mail server is listed in the blacklist. How to unblock it quickly?
【信息安全法律法規】複習篇
The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
跟奥巴马一起画方块(Lua)
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
LeetCode1051(C#)
第2章搭建CRM项目开发环境(数据库设计)
【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
本周小贴士131:特殊成员函数和`= default`
Devops' operational and commercial benefits Guide
网络攻防复习篇
本周小贴士#141:注意隐式转换到bool
LeetCode 535(C#)
浅谈 Apache Doris FE 处理查询 SQL 源码解析
What is cloud computing?
On Apache Doris Fe processing query SQL source code analysis
[Fantan] how to design a test platform?
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
【分布式理论】(二)分布式存储