so the question How to add border around linear layout except at the bottom? answers my question partially but i cant seem to figure out how to make the corners round ..
Asked
Active
Viewed 247 times
0

Community
- 1
- 1

Jacob Anthony Tonna
- 515
- 3
- 13
- 27
-
Did you try this : http://stackoverflow.com/q/6514114/693752 ? – Snicolas May 28 '13 at 06:20
3 Answers
1
In your linear layout
android:background="@drawable/bkg"
Define the below xml in drawable folder.
bkg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#10EB0A"/>
<stroke android:width="3dp"
android:color="#0FECFF" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>

Raghunandan
- 132,755
- 26
- 225
- 256
1
Create a XML file named
round_border
in your layout folder.Now put this code in your XML file :
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="4dp" android:color="#FF00FF00" /> <solid android:color="#ffffff" /> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="10dp" />
Now use this file as a background of your
LinearLayout
like this :<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="20dip" android:background="@drawable/round_border">

Vipul Purohit
- 9,807
- 6
- 53
- 76
-
just one problem my app has a background image anyway to just allow the border to be seen? – Jacob Anthony Tonna May 28 '13 at 06:30
-
@JacobAnthonyTonna are you looking for image with rounded corners? – Raghunandan May 28 '13 at 06:32
-
@JacobAnthonyTonna i don't think you can both set for linear layout. I guess you are looking for image with rounded corners – Raghunandan May 28 '13 at 06:35
-
-
wait theres one huge problem i cant have 2 items in there without one moving or overlapping the other... – Jacob Anthony Tonna May 29 '13 at 00:38
0
this is a custom Drawable you can use:
class RoundedImageDrawable extends Drawable {
private Bitmap mBitmap;
private Matrix mMatrix;
private Path mPath;
private float mRx;
private float mRy;
public RoundedImageDrawable(Resources res , int id, float rx, float ry) {
mBitmap = BitmapFactory.decodeResource(res, id);
mMatrix = new Matrix();
mPath = new Path();
mRx = rx;
mRy = ry;
}
@Override
protected void onBoundsChange(Rect bounds) {
RectF src = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
RectF dst = new RectF(bounds);
mMatrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
mPath.addRoundRect(dst, mRx, mRy, Direction.CW);
}
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.clipPath(mPath);
canvas.drawBitmap(mBitmap, mMatrix, null);
canvas.restore();
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
and use it in your Activity:
LinearLayout ll = findViewById(R.id.layout);
Drawable d = new RoundedImageDrawable(getResources(), R.drawable.background, 20, 20);
ll.setBackgroundDrawable(d);

pskink
- 23,874
- 6
- 66
- 77