2

I have a linearlayout and an imageview inside. The linearlayout has rounded corners. I want my image to be at the very top of the view, but when the image appears, the corners are not longer rounded. What can I do for this? I know in iOS there is a clip subviews option for the container (UIView). But not sure with Android.

 <LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"   
    android:orientation="vertical"
    android:gravity="top"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"  
    android:background="@drawable/cell_rounded_edges">  
    <ImageView
        android:id="@+id/prodImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:gravity="top"   
        android:focusable="false"
        android:clickable="false"   
        android:adjustViewBounds="true"       
        />
.....and so on
Jesse
  • 2,674
  • 6
  • 30
  • 47
  • 1
    I think this is exactly what you are looking for: http://stackoverflow.com/questions/5574212/android-view-clipping – 0gravity Jul 16 '12 at 21:44
  • 1
    thanks, i needed to round the corners of the image for this to work. google needs to fix this issue. the clipChildren should work, but doesnt. – Jesse Jul 16 '12 at 22:37

2 Answers2

1

Any ViewGroup (which includes LinearLayout) has a boolean XML attribute of android:clipChildren (also settable programmatically with setClipChildren(boolean)) but according to the documentation, this is by default set to true.

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
0

I found a great and easy solution !

I had an image in the top of my layout where only the top corners had to be round (simulate the clip to subviews in iOS), since my layer have all of his corners round.

On my Image Background:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#e3e3e3"/>
<corners android:bottomRightRadius="0dip"
         android:bottomLeftRadius="0dip"
         android:topLeftRadius="25dip"
         android:topRightRadius="25dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

On my Layer Background:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFF"/>
<corners android:radius="25dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape>
Marc
  • 11,341
  • 3
  • 27
  • 30