【发布时间】:2013-11-29 10:18:21
【问题描述】:
我在为RelativeLayout 设置背景图像时遇到问题。细节问题:
- 我的用户界面中有RelativeLayout 和Button。当按钮点击然后显示画廊的意图。从该图库中选择 1 张图片,我想将该图片设置为 RelativeLayout 背景。
我可以调用图库的意图,但我仍然无法将该图片设置为 RelativeLayout 背景。请帮帮我
编辑(这是我从图库意图设置 ImageView 的示例代码):
final ImageView img = (ImageView) findViewById(R.id.img);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
//img.setImageResource(Intent.);
Drawable dr = new BitmapDrawable(SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
//Integer selectedImageUri;
//Integer[] bg = {selectedImageUri};
if (resultCode == RESULT_OK){
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
ImageView img = (ImageView) findViewById(R.id.img);
img.setImageURI(selectedImageUri);
那么如何将该图片设置为不是ImageView的图像,而是作为RelativeLayout背景
【问题讨论】:
-
请粘贴您的代码
标签: android android-layout android-gallery