0

I found a lot of methods to create round corners on ImageView. They all work while the imageView and its parent layout are set to wrap_content or match_parent. But the layout of my application requires a fixed height and width, so those methods don't work.

Here's my XML (the "Preview" ImageView MUST align the "Name" text field on the top and "Phone" on the bottom. I tried setting the imageview and its parent layout to "wrap content" and set a MaxWidth and MaxHeight for the ImageView, but it did not work horizontally, so the 3 text fields on the right get pushed off the screen. I need some help to re-construct the layout the way it works with "wrap_content" for "preview" and its parent layout OR find a find a method for creating round corners that works with a fixed layout size (actually I tried 3 or 4).

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="60dp"
    android:layout_height="158dp"
    android:layout_alignParentRight="true"
    android:layout_marginRight="7dp"
    android:layout_marginTop="38dp"
    android:layout_toRightOf="@+id/RL_ImageHolder" >

    <EditText
        android:id="@+id/Name"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:background="@drawable/form_m_6"
        android:gravity="top"
        android:hint="Name"
        android:padding="5dp" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/Surname"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/Name"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="19dp"
        android:background="@drawable/form_m_6"
        android:gravity="top"
        android:hint="Surname"
        android:padding="5dp" />

    <EditText
        android:id="@+id/etPhone"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="5dp"
        android:background="@drawable/form_m_6"
        android:gravity="top"
        android:hint="Phone number"
        android:inputType="phone"
        android:padding="5dp" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/RL_ImageHolder"
    android:layout_width="140dp"
    android:layout_height="158dp"

    android:layout_alignBottom="@+id/relativeLayout2"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/relativeLayout2"
    android:layout_marginLeft="10dp" >

    <ImageView
        android:id="@+id/imgPreview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="140dp"
        android:maxHeight="160dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="Preview"

         />
</RelativeLayout>
Droidman
  • 11,485
  • 17
  • 93
  • 141
  • How do you have implemented the round corners on ImageView? I think you should implement a custom View and override the onMeasure method. – moondroid Dec 20 '12 at 08:32
  • I tried all the solutions from that topic http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners They all work if I have a stand-alone ImageView but don't work in complex layouts – Droidman Dec 20 '12 at 09:44

1 Answers1

0

tried to change the layout as below

   <RelativeLayout
        android:id="@+id/RL_ImageHolder"
        android:layout_width="140dp"
        android:layout_height="160dp"
        android:layout_alignBottom="@+id/relativeLayout2"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/relativeLayout2"
        android:layout_marginLeft="10dp" >

        <ImageView
            android:id="@+id/imgPreview"
            android:layout_width="140dp"
            android:layout_height="160dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:contentDescription="Preview"

             />
    </RelativeLayout>
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
  • no luck.. I also managed to set width and height of the image and its parent to wrap_content by placing both RelativeLayouts inside a Linear and setting the weight to 50%.. rounded corners just don't want to work WTF o_0 – Droidman Dec 20 '12 at 08:54