当前位置:网站首页>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"/>


边栏推荐
- 【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
- 电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
- 使用Stace排除故障的5种简单方法
- Repair method of firewall system crash and file loss, material cost 0 yuan
- Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
- DNS 系列(一):为什么更新了 DNS 记录不生效?
- Solidity函数学习
- Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
- 99%的人都不知道|私有化部署还永久免费的即时通讯软件!
- 【信息安全法律法規】複習篇
猜你喜欢

With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore

状态模式 - Unity(有限状态机)

MRS离线数据分析:通过Flink作业处理OBS数据

AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究

【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会

Linux 安装mysql8.X超详细图文教程

Sator推出Web3游戏“Satorspace” ,并上线Huobi

PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight

How to choose the appropriate automated testing tools?
随机推荐
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
How to mount the original data disk without damage after the reinstallation of proxmox ve?
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
使用popupwindow創建对话框风格的窗口
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
Biped robot controlled by Arduino
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
99% of users often make mistakes in power Bi cloud reports
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
DNS series (I): why does the updated DNS record not take effect?
Skimage learning (1)
Flash build API service
LeetCode 515(C#)
【信息安全法律法規】複習篇
L1-028 判断素数(Lua)
LeetCode刷题day49
Flask搭建api服务
Establishment of solid development environment
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?