user3164083
user3164083

Reputation: 1073

Add View to RelativeLayout in OnCreate()

EDIT Please view the bottom of this question where it says EDIT. Because i solved the issue by moving the <com.edmodo.cropper.CropImageView from the inner layout, to the root layout. But now I still need to get the added child views into the inner layout called "Dress" to get them in the screenshot. Thanks.

I take a screenshot of a RelativeLayout. The screenshot must show only the size of the ImageView that is inside the RelativeLayout. The reason I cannot take a screenshot of the ImageView itself is because I have other child views that get added on top of the ImageView that need to be in the screenshot.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:longClickable="true"
    android:onClick="deleteImage"
    android:background="@android:color/transparent" 
    tools:context=".DressingRoomActivity" >

    <RelativeLayout
        android:id="@+id/Dress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent" >

    <com.edmodo.cropper.CropImageView 
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/CropImageView"
    android:background="@android:color/transparent" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/imageViewDress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:adjustViewBounds="true"
        android:background="#00CED1"
        android:padding="10dp"
        android:scaleType="centerInside" />

    </RelativeLayout>
</RelativeLayout>

My code to take the Screenshot:

public Bitmap takeScreenshot() {
        View v = findViewById(R.id.Dress);
        v.setDrawingCacheEnabled(true);
        return v.getDrawingCache();
    }

EDIT: I do not get the child views in the screenshot. I used to take a screenshot of the RootView of the activity to get them, but i do not want the actionbar, so I need to take a screenshot of the inner relativeLayout. But as you can see I add the child view to the Rootview like this:

photoSorter = new MultitouchImagesView(this.getApplicationContext());
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            addContentView(photoSorter, params);

Can I change that to add them to my RelativeLayout called "Dress"?

Thanks

Upvotes: 0

Views: 433

Answers (2)

priyanka morisetti
priyanka morisetti

Reputation: 267

android:padding="10dp" remove this line from your xml imageview code ...

Upvotes: 0

Chirag Ghori
Chirag Ghori

Reputation: 4231

Remove padding attribute from your ImageView and Change ScalType to android:scaleType="fitXY"

<ImageView
    android:id="@+id/imageViewDress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:adjustViewBounds="true"
    android:background="#00CED1"
    android:scaleType="fitXY" />

Upvotes: 2

Related Questions