ImageSwitcher的使用(一):与Gallery配合使用
来源:互联网 发布:沉迷网络的事例 编辑:程序博客网 时间:2024/05/11 19:07
package com.example.androidtest;import android.os.Bundle;import android.app.Activity;import android.content.Context;import android.content.res.TypedArray;import android.view.View;import android.view.ViewGroup;import android.view.ViewGroup.LayoutParams;import android.view.animation.AnimationUtils;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher.ViewFactory;import android.util.Log;public class MainActivity extends Activity implements ViewFactory {Integer[] imageIDs = {R.drawable.ic_launcher, R.drawable.ic_launcher};private ImageSwitcher imageSwitcher;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageSwitcher = (ImageSwitcher)findViewById(R.id.switcher1);imageSwitcher.setFactory(this);imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left));imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));Gallery gallery = (Gallery)findViewById(R.id.gallery1);gallery.setAdapter(new ImageAdapter(this));gallery.setOnItemClickListener(new OnItemClickListener() {public void onItemClick(AdapterView<?> parent, View v, int position, long id){imageSwitcher.setImageResource(imageIDs[position]);Log.d("wuli", "position:" + position + " id:" + id);}});}public View makeView(){ImageView imageView = new ImageView(this);imageView.setBackgroundColor(0xff000000);imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));return imageView;}public class ImageAdapter extends BaseAdapter{private Context context;private int itemBackground;public ImageAdapter(Context c){context = c;TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);itemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);a.recycle();}public int getCount(){return imageIDs.length;}public Object getItem(int position){return position;}public long getItemId(int position){return position;}public View getView(int position, View convertView, ViewGroup parent){ImageView imageView = new ImageView(context);Log.d("wuli", "position:" + position);imageView.setImageResource(imageIDs[position]);imageView.setScaleType(ImageView.ScaleType.FIT_XY);imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));imageView.setBackgroundResource(itemBackground);return imageView;}}}
在res\values下新建styleable.xml:
<?xml version="1.0" encoding="UTF-8"?><resources> <declare-styleable name="Gallery1"> <attr name="android:galleryItemBackground" /> </declare-styleable> </resources>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff000000" > <ImageSwitcher android:id="@+id/switcher1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" /> <Gallery android:id="@+id/gallery1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout>
0 0
- ImageSwitcher的使用(一):与Gallery配合使用
- ImageSwitcher配合Gallery的简单使用
- Gallery与ImageSwitcher的综合使用
- Gallery 与ImageSwitcher的结合使用
- Gallery 与ImageSwitcher的结合使用
- ImageSwitcher 和 Gallery 的使用
- ImageSwitcher和Gallery的使用
- gallery ,imageSwitcher 结合使用
- Android中Gallery和ImageSwitcher的使用
- Android中Gallery和ImageSwitcher的使用
- android中画廊视图Gallery和ImageSwitcher组件的使用
- 使用ImageSwitcher和Gallery实现图片的浏览
- 使用ImageSwitcher和Gallery实现图片的浏览
- ImageSwitcher&Gallery组件和GridView组件的使用
- Gallery的使用(一)
- Gallery单独使用,Gallery和ImageSwitcher组件结合使用的例子
- Android ImageSwitcher和Gallery 综合使用
- Android ImageSwitcher和Gallery 综合使用
- VC判断当前用户有无Administrator的权限
- FATAL: Could not read from boot medium. System halted.
- 人人都能成为黑客:不是游戏打不过小学生了,而是编码也不如小学生咯 !
- 贪心磁盘存储问题
- ORA-01506: missing or illegal database name
- ImageSwitcher的使用(一):与Gallery配合使用
- 恳请万能的高手追寻桂辉(500强(深圳)前高管-欠钱做老赖还危及他人人身安全)
- 第二题输入7个45随机数
- VC替换桌面IE图标[源码]
- 01背包、完全背包、多重背包
- 旋转字符串问题
- 0801
- CSS 宽度自适应总结
- 随机函数(2)