Android 图像位于背景后面
我想像下面的图像输出 我有像这样的背景图像 现在我想把图像放回原处。相机部件图像应位于用户的上方。我尝试下面的代码,但不工作Android 图像位于背景后面,android,Android,我想像下面的图像输出 我有像这样的背景图像 现在我想把图像放回原处。相机部件图像应位于用户的上方。我尝试下面的代码,但不工作 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/user" android:background="@
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user"
android:background="@drawable/changephoto"
/>
我也尝试了framelayout,但不起作用。您应该使用用户图像作为
ImageView背景图像
,使用相机图像作为ImageView资源图像
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/changephoto"
android:background="@drawable/user" />
创建以下透明图像:
你不能用这种方式做你想做的事 解决方案是使用三张分开的图像,一张用于白色背景,一张用于相机图像,最后一张用于实际轮廓图像
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="your background image" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="profile image" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="camera photo"
android:layout_gravity="bottom|left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Photo"/>
</FrameLayout>
FrameLayout或相对布局应该可以为您解决此问题。为相机部件和用户部件使用不同的图像视图请确保您的相机图像是透明的,并且是.png格式。
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case 100:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
ImageView imgv = (ImageView) findViewById(R.id.imageView1);
// imgv.setImageBitmap(yourSelectedImage);
Drawable d = new BitmapDrawable(getResources(),
yourSelectedImage);
imgv.setBackgroundDrawable(d);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="your background image" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="profile image" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="camera photo"
android:layout_gravity="bottom|left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Photo"/>
</FrameLayout>