0

我想要如下图所示的输出。

在此处输入图像描述

我有像这样的背景图片

在此处输入图像描述

现在我想把图像放回去。相机部分图像应在用户上方。我尝试下面的代码但不工作

<ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/user"
            android:background="@drawable/changephoto"
             />

我也尝试 framelayout 但不工作。

4

3 回答 3

0

创建以下透明图像:

在此处输入图像描述

<ImageView
        android:id="@+id/imageView1"
        android:onClick="setimag"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/back"
        android:background="@drawable/ic_launcher" />

你的图像ic_launcher在哪里,因为你不知道

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);
            }
        }
    }
于 2013-04-30T12:59:30.567 回答
0

您应该使用 User image asImageView Background image和 Camera image asImageView Resource Image

<ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/changephoto"
            android:background="@drawable/user" />
于 2013-04-30T12:53:05.407 回答
0

不能用这种方式做你想做的事。

解决方案是使用三张分开的图像,一张用于白色背景,一张用于相机图像,最后一张用于实际的个人资料图像

<?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>
于 2013-05-01T14:23:10.003 回答