ImageSwitcher配合Gallery读取手机相册
public class mainactivity extends Activity implements
OnItemSelectedListener, ViewFactory {
private ImageSwitcher is;
private Gallery gallery;
private Integer[] mThumbIds = { R.drawable.b, R.drawable.c,
R.drawable.d, R.drawable.f, R.drawable.g,
};
private Integer[] mImageIds = { R.drawable.b, R.drawable.c,
R.drawable.d, R.drawable.f, R.drawable.g, };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
is = (ImageSwitcher) findViewById(R.id.switcher);
is.setFactory(this);
is.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
is.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemSelectedListener(this);
}
@Override
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return i;
}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.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 i = new ImageView(mContext);
i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.e);
return i;
}
private Context mContext;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
is.setImageResource(mImageIds[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="doc.guandang.net;
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageSwitcher android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
<Gallery android:id="@+id/gallery"
android:background
ImageSwitcher 类必须设置一个 ViewFactory,主要用来将显示的图片和父窗口区分开来,因此需要实现 ViewSwitcher.ViewFactory 接口,通过 makeView()方法来显示图片,这里会返...
Android-ImageSwitcher图片切换_计算机软件及应用_IT/计算机_专业资料。Android-ImageSwitcher图片切换AVD SDK Activity_main.xml <LinearLayout xmlns:android="http:/...
Android 控件ImageSwitcher_IT/计算机_专业资料。Android 控件ImageSwitcherImageSwitcher 是 Android 中控制图片展示效果的一个控件,效果图如下: 一、重要方法 ...
Android-Gallery和ImageSwitcher结合完成图片拖动和切换_计算机软件及应用_IT/计算机_专业资料。Android-Gallery和ImageSwitcher结合完成图片拖动和切换.doc...
由麦可网整理,转载请注明出处 Android 之 Gallery 及 ImageSwitcher 组件 Gallery 组件一般用于显示图像列表,因此也可称相册组件 Gallery 与 GridView 的区别是 ...
相册(ImageSwitcher&Gallery) 第一步:布局文件main.xml中加入ImageSwitcher和Gallery 控件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:...
} return newbmp; = (ImageSwitcher)findViewById(R.id.switcher01); mSwitcher.setFactory(this); mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, ...
Android ImageSwitcher 学习笔记 ImageSwitcher 是 Android 中控制图片展示效果的一个控件,如:幻灯片效果...,颇有感觉啊。 做相册一绝 源码下载 一、重要方法 ...
Android 之Gallery及ImageSwitcher组件 Gallery 组件一般用于显示图像列表,因此也可称相册组件 Gallery 与GridView 的区别是Gallery只能水平显 示一行,而且支持水平...
(ImageSwitcher) findViewById(R.id.switcher); 33 mSwitcher.setFactory(this); 34 mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, 35 Android.R.anim...
热门文档