Reactgular
Reactgular

Reputation: 54751

Resize height of ImageView by finger

I have an activity that shows the camera preview, and an ImageView of the last image taken.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<ImageView
        android:id="@+id/stitch_preview"
        android:layout_width="fill_parent"
        android:layout_height="128dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:scaleType="center"
        android:visibility="gone"/>

<SurfaceView
        android:id="@+id/camera_preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/stitch_preview"/>

Right now the ImageView is fixed to 128dp height. Is difficult to make this view resizable by dragging your finger down on the ImageView.

I've been searching for various hints, but everything I find relates to pulling out a hidden view. I can't seem to find an example of resizing an already visible view.

Tutorial for doing a pull-down "view" in android?

How to resize a custom view programmatically?

Upvotes: 0

Views: 1194

Answers (1)

dd619
dd619

Reputation: 6170

By assuming that your ImageView is visible,Following steps may help you-

1)Pinch-zoom your ImageView or actually resize your imageview using LayoutParams using multitouch(You can resize Imageview as per your standard bound).

2)Take capture of your imageview using following code

ImageView iv=(ImageView)findViewbyId(R.id.ImageView1)

....

iv.setDrawingCacheEnabled(true);
                // Set the layout manually to after resizing or pinch zoom
                iv.layout(0, 0, x, y);
                // Set the quality to high
                iv.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
                // Build the cache, get the bitmap and close the cache
                iv.buildDrawingCache(true);
                Bitmap bmBarChart = gv.toBitmap();

the above code will return you the re-sized bitmap image.

3)Now save this image and set it to your ImageView

i have already resized the visible view before but i had slightly different requirement than you

Upvotes: 1

Related Questions