如何调用系统gallery打开指定文件夹中的图片???
解决方案 »
- Android中Movie类播放Gif问题
- 关于android手机显示文件名的时候 出现出错误的现象
- android 不可以自己创建资源目录吗?
- android GPS函数问题
- 菜鸟想学习安卓,求推荐的东西
- Android直播app用什么技术可以做到延迟小一些?
- Eclipse 中DDMS报错
- 学生党:关于ScrollView嵌套ListView出现的控件位置不一致问题
- 访问不到某api的问题,求教
- cannot cast 'android.support.v4.app.FragmentTransaction' to 'android.app.Fragmen
- 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);