-1

I want to create a background that is an image and also give it rounded corners. I have the following code. the background image shows but there is no rounded corners.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="20dp" />
        </shape>
    </item>

    <item>
        <bitmap
            android:src="@drawable/tabs_pattern_diagonal"
            android:tileMode="repeat" />
    </item>

</layer-list>

I have tried changing the order of the times but it made no difference

edit

I dont have an imageview. this layerlist is being applied as a background to a linearlayout

124697
  • 22,097
  • 68
  • 188
  • 315
  • possible duplicate of [Bitmap in ImageView with rounded corners](http://stackoverflow.com/questions/18229358/bitmap-in-imageview-with-rounded-corners) – flx Sep 11 '13 at 11:23
  • here is your solution http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners – Developer Sep 11 '13 at 11:37

3 Answers3

1

You can use this library if you don't want to implement rounded corners yourself.

0

You can try following :

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
        bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
  }

Source

You can also refer to article by Romain Guy

Ritesh Gune
  • 16,629
  • 6
  • 44
  • 72
-1

try this:

    <item>
        <shape android:shape="rectangle" android:padding="10dp" >
        <corners
         android:bottomRightRadius="15dp"
         android:bottomLeftRadius="15dp"
      android:topLeftRadius="15dp"
      android:topRightRadius="15dp"/>
        </shape>
    </item>

    <item>
        <bitmap
            android:src="@drawable/tabs_pattern_diagonal"
            android:tileMode="repeat" />
    </item>

</layer-list>
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42