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

以上将带我们进入设备中的图库应用程序,因此我们将获得占据设备整个显示的图库屏幕。但我想在小布局中显示该图库应用程序视图(就像我展示的那样在下图中,而不是 EditText,Buttons ,我想在那个小布局中获取我的设备库屏幕)。这样我就可以给用户一种他没有离开应用程序的感觉。

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

是否有可能在android中实现这一点?

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

但我想在自定义视图中显示图库页面。在此处输入图像描述

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

我怎样才能做到这一点?

请建议

谢谢

4

2 回答 2

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
}
于 2013-02-08T07:41:06.677 回答
1

请转到此链接

并修改您的 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 的高度和宽度。

于 2013-02-08T07:44:00.120 回答