如何调用系统gallery打开指定文件夹中的图片???
解决方案 »
- 分享一些android电子版书籍,完全免费下载!
- 01-31 15:37:45.759: E/AndroidRuntime(3485): Caused by: java.lang.UnsatisfiedLink
- android 在一个activity中点击GridView中的一个Item一(包含图片和名字),
- 创建模拟器时设置的SD卡怎么使用?
- 如何将数据库文件导入到Android 真机中?
- Android调用系统音乐播放器的问题
- 菜鸟问问
- UBUNTU编译XBMC for android编译不过
- 精通Android4.0视频教程,感兴趣就进来
- 寻Android底层及应用程序开发者合作
- JNI例子碰到的问题:System.loadLibrary失败
- 初学Android,不理解Handler和线程有什么区别,求教
Intent it = new Intent(Intent.ACTION_VIEW);
Uri mUri = Uri.parse("file://"+file.getPath());
it.setDataAndType(mUri, "image/*");
startActivity(it);
2. ComponentName componentName=new ComponentName("com.cooliris.media","com.cooliris.media.Gallery");
Intent intent=new Intent();
intent.setComponent(componentName);
File file=new File("/sdcard/IMG/1.jpg");
Uri mUri = Uri.parse("file://"+file.getPath());
intent.setData(mUri);
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Gallery
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id="@+id/gallery_id"
android:layout_x="43px"
android:layout_y="142px" />
</LinearLayout>
package com.yezijp.gallerytest;import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;public class GalleryTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) this.findViewById(R.id.gallery_id);
gallery.setAdapter(new GalleryAdapter(this));
}
public class GalleryAdapter extends BaseAdapter {
private Context context;
private int[] myImages = {
R.drawable.a1,
R.drawable.a2,
R.drawable.a3,
R.drawable.a4};
public GalleryAdapter (Context c) {
this.context = c;
} @Override
public int getCount() {
return myImages.length;
} @Override
public Object getItem(int position) {
return position;
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(this.context);
imageView.setImageResource(this.myImages[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));
return imageView;
}
}
}
之后关联控件并设置适配器
Gallery gallery = (Gallery) this.findViewById(R.id.gallery_id);
gallery.setAdapter(new GalleryAdapter(this));之后在自定义适配器GalleryAdapter中设置图片资源的数组
imageView.setImageResource(this.myImages[position]);
options.inSampleSize=0;
Bitmap bitmap=BitmapFactory.decodeFile("图片文件路径",options);
ImageView imgView=new ImageView(context);
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
//imgView.setLayoutParams(new Gallery.LayoutParams(100, Gallery.LayoutParams.FILL_PARENT));
imgView.setImageBitmap(bitmap);