jayrambhia / CropperNoCropper

Instagram Style Image Cropper for Android (Library)
http://www.jayrambhia.com/project/nocropper-library
Apache License 2.0
474 stars 99 forks source link

com.fenchtose.nocropper.CropperView height issue #2

Closed tuhin10 closed 8 years ago

tuhin10 commented 8 years ago

it seems your are calculating the CropperView based on the width of the view. Now the problem is I'm not able to make the view center in the screen.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottom_frame"
    android:layout_alignParentTop="true" >
    <com.fenchtose.nocropper.CropperView
        android:background="#ff282828"
        android:id="@+id/imageview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:grid_opacity="0.8"
        app:grid_thickness="1.1dp"
        app:grid_color="@color/colorAccent"/>
    <ImageView
        android:id="@+id/snap_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="16dp"
        android:padding="8dp"
        android:layout_gravity="left|bottom"
        android:background="@drawable/black_transp_circ_ripple"
        android:scaleType="center"
        android:src="@mipmap/ic_crop_free_white_24dp"/>
    <ImageView
        android:id="@+id/rotate_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:padding="8dp"
        android:layout_margin="16dp"
        android:layout_gravity="right|bottom"
        android:background="@drawable/black_transp_circ_ripple"
        android:scaleType="center"
        android:src="@mipmap/ic_rotate_right_white_24dp"/>
</FrameLayout>
<LinearLayout
    android:id="@+id/bottom_frame"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="#ff212121"
    android:padding="9dp"
    android:layout_alignParentBottom="true"
    android:gravity="center_vertical"
    android:orientation="horizontal">
    <Button
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="Upload Image"
        android:id="@+id/image_button"/>
    <Button
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="Crop"
        android:id="@+id/crop_button"/>
</LinearLayout>
</RelativeLayout>

screenshot_2015-11-19-02-18-49

tuhin10 commented 8 years ago

I want to remove the white space between lower buttons and crop view, by center aligning the cropview.

jayrambhia commented 8 years ago

You're right. It does calculate height based on the width to make it square. Maybe it wouldn't work properly in Landscape mode. You can solve your problem by changing your layout.

If you want to keep the cropper in center, use layout_gravity="center" and since it is a square, you would want your FrameLayout height to wrap_content.

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_frame"
android:layout_alignParentTop="true" >
<com.fenchtose.nocropper.CropperView
    android:background="#ff282828"
    android:id="@+id/imageview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center"
    app:grid_opacity="0.8"
    app:grid_thickness="1.1dp"
    app:grid_color="@color/colorAccent"/>
<ImageView
    android:id="@+id/snap_button"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_margin="16dp"
    android:padding="8dp"
    android:layout_gravity="left|bottom"
    android:background="@drawable/black_transp_circ_ripple"
    android:scaleType="center"
    android:src="@mipmap/ic_crop_free_white_24dp"/>
<ImageView
    android:id="@+id/rotate_button"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:padding="8dp"
    android:layout_margin="16dp"
    android:layout_gravity="right|bottom"
    android:background="@drawable/black_transp_circ_ripple"
    android:scaleType="center"
    android:src="@mipmap/ic_rotate_right_white_24dp"/>
</FrameLayout>
jayrambhia commented 8 years ago

Closed in favor of https://github.com/jayrambhia/CropperNoCropper/issues/3