如何在android中的自定义视图中显示移动图库页面?

时间:2013-02-08 07:35:06

标签: android

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);

上面将我们带到我们设备中的Gallery应用程序,因此我们将获得占据设备整个显示的Gallery屏幕。但我想在小版面中显示该Gallery应用程序视图(某些东西)就像我在下面的图片中所示,而不是EditText,Buttons,我希望在那个小布局中获得我的设备图库屏幕。)因此,我可以让用户感觉他没有退出应用程序。

我在其中一个IPAD应用程序(HelloAlbums)中看到了这个。

有可能在android中实现这个吗?

我使用上面的代码来调用电话库应用程序。

但我想在自定义视图中显示图库页面。enter image description here

假设我在下面使用的视图中。

我怎样才能做到这一点?

请建议

由于

2 个答案:

答案 0 :(得分:4)

试试这个

public void ChoosePicture(View v) {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, 1);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case 1:
     {
      if (resultCode == RESULT_OK)
      {
        Uri photoUri = data.getData();
        if (photoUri != null)
        {
        try {
              String[] filePathColumn = {MediaStore.Images.Media.DATA};
              Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null); 
              cursor.moveToFirst();
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String filePath = cursor.getString(columnIndex);
              cursor.close();
              bMap_image = BitmapFactory.decodeFile(filePath);
              ImageView img = (ImageView) findViewById(R.id.gallery1);
              img.setImageBitmap(bMap_image);


     }catch(Exception e)
      {}
      }
    }// resultCode
    }// case 1
    }// switch, request code
}

答案 1 :(得分:1)

请转到link

并通过

修改您的imageadapter类
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView i = new ImageView(mContext);

    i.setImageResource(mImageIds[position]);
    i.setLayoutParams(new Gallery.LayoutParams(150, 100));//make change of this size
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    i.setBackgroundResource(mGalleryItemBackground);

    return i;
}

只需更改layoutParams的高度和宽度。