Android 安卓:勇敢的一击效果
我已经在ArrayList中列出了图像位置(SD卡图像路径)。我是否可以将其传递给Gallary,让用户浏览图像 如果没有,我如何实现类似的东西 谢谢你的帮助。提前谢谢你的时间Android 安卓:勇敢的一击效果,android,gallery,swipe,Android,Gallery,Swipe,我已经在ArrayList中列出了图像位置(SD卡图像路径)。我是否可以将其传递给Gallary,让用户浏览图像 如果没有,我如何实现类似的东西 谢谢你的帮助。提前谢谢你的时间 PS:我在网上搜索,但找不到我想要的东西。谢谢。您可以直接使用多媒体资料课程。下面是一些代码片段,但在线上有大量的示例可供使用 onCreate(Bundle b)应该如下所示 @Override public void onCreate(Bundle savedInstanceState) { super.on
PS:我在网上搜索,但找不到我想要的东西。谢谢。您可以直接使用
多媒体资料
课程。下面是一些代码片段,但在线上有大量的示例可供使用
onCreate(Bundle b)
应该如下所示
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
这里是main.xml
<?xml version="1.0" encoding="utf-8"?>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
适配器
类应如下所示
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return mImageIds.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(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
这个例子是可用的。看看它。但这没有滑动效果吗??我们需要点击缩略图。我需要像在默认的Android Gallary中一样具有滑动效果。它具有类似的滑动效果。否则,请看coverflow。它扩展了gallery。thumnails仪式将提供滑动效果??但我希望图像具有滑动效果。我甚至不想要缩略图。只需在全屏显示图像,并使用fling效果即可。不过,覆盖流看起来不错。尝试几个例子来代替imageView.setLayoutParams(新的Gallery.LayoutParams(150100));保持它们填充父对象和内容在150100的位置,你可以得到完整的图像,而不是缩略图。现在我需要弄清楚如何传递sd卡URI,而不是drawables中的图像。谢谢:)
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return mImageIds.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(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}