Set Width and Height from Bitmap or ImageView to CustomView

Keywords: java android view android-custom-view

Question: 

I'm trying to get Width and Height of Bitmap and set them as Layout Parameter of CustomView

JAVA :

 private void setBg() {
        drawView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        drawView.getLayoutParams().height = orginalBitmap.getHeight();
        drawView.getLayoutParams().width = orginalBitmap.getWidth();
        relativeLayout.addView(drawView);
    }

XML :

   <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottom"
        android:layout_below="@+id/clear">

        <ImageView
            android:id="@+id/fullimg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center_horizontal|center_vertical"
            android:adjustViewBounds="true" />

        <RelativeLayout
            android:id="@+id/relative"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center_horizontal|center_vertical"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical" />
    </RelativeLayout>

But the code above doesn't work, when I run the app I get this

enter image description here

the emojis, for example, should stop right in the corner of image view but instead of that it still appears in the two empty spaces.

Answers: