imageswitcher+gallay实现相册功能
来源:互联网 发布:北大青鸟软件学校 编辑:程序博客网 时间:2024/05/29 15:52
说明:
使用ImageSwitcher控件+gallary控件可以实现点击下方gallary控件更换上面imageswitcher控件图片展示的功能。
代码演示:
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 version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="#55000000"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp"
/>
</RelativeLayout>
使用ImageSwitcher控件+gallary控件可以实现点击下方gallary控件更换上面imageswitcher控件图片展示的功能。
代码演示:
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 version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="#55000000"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp"
/>
</RelativeLayout>
0 0
- imageswitcher+gallay实现相册功能
- ImageSwitcher和HorizontalScrollView实现相册
- android教程之教你用Gallery+ImageSwitcher实现相册功能 (一)
- Android利用Gallery和ImageSwitcher实现在线相册图片预览功能(异步加载图片)
- 利用Gallery和ImageSwitcher实现在线相册图片预览功能(异步加载图片)
- Gallay
- Gallery 和ImageSwitcher实现照片墙功能
- ImageSwitcher实现图片浏览切换功能
- android实现图片相册功能
- iOS 相册备份功能实现
- 自定义UICollectionViewFlowLayout实现相册功能
- Hexo+Github实现相册功能
- ionic 相册功能的实现
- 使用ImageSwitcher实现点击按钮浏览图片功能
- Android 基础控件之ImageSwitcher、Gallery功能的实现
- ImageSwitcher and Gallery 组合作相册
- jQuery实现仿QQ相册功能
- jquery插件实现qq相册功能
- 如何使用Linux的Crontab定时执行PHP脚本的方法
- 分布式系统中failover相关测试要点
- 选择不相交区间(活动安排问题)(贪心)(HDU2037)
- junit入门
- 【Struts2】入门知识点
- imageswitcher+gallay实现相册功能
- android 常用命令
- 使用carrierwave时判断图片尺寸
- 动态调整UITableViewCell的高度及字体大小设置
- 蓝桥杯 杨辉三角形
- CSS中overflow隐藏、滚动条、换行等用法
- iOS开发, 关于nslog的几种用法
- Junit单元测试问题 junit.framework.AssertionFailedError: Method "test" not found at android.test.AndroidTes
- angularjs中$http、$location、$watch及双向数据绑定学习实现简单登陆验证