Round Border Linerlayout
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 ..
Solution 1:
Create a XML file named
round_border
in your layout folder.Now put this code in your XML file :
<shapexmlns:android="http://schemas.android.com/apk/res/android"><strokeandroid:width="4dp"android:color="#FF00FF00" /><solidandroid:color="#ffffff" /><paddingandroid:left="7dp"android:top="7dp"android:right="7dp"android:bottom="7dp" /><cornersandroid: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">
Solution 2:
In your linear layout
android:background="@drawable/bkg"
Define the below xml in drawable folder.
bkg.xml
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solidandroid:color="#10EB0A"/><strokeandroid:width="3dp"android:color="#0FECFF" /><paddingandroid:left="5dp"android:top="5dp"android:right="5dp"android:bottom="5dp"/><cornersandroid:bottomRightRadius="7dp"android:bottomLeftRadius="7dp"android:topLeftRadius="7dp"android:topRightRadius="7dp"/></shape>
Solution 3:
this is a custom Drawable you can use:
classRoundedImageDrawableextendsDrawable {
private Bitmap mBitmap;
private Matrix mMatrix;
private Path mPath;
privatefloat mRx;
privatefloat mRy;
publicRoundedImageDrawable(Resources res , int id, float rx, float ry) {
mBitmap = BitmapFactory.decodeResource(res, id);
mMatrix = newMatrix();
mPath = newPath();
mRx = rx;
mRy = ry;
}
@OverrideprotectedvoidonBoundsChange(Rect bounds) {
RectFsrc=newRectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
RectFdst=newRectF(bounds);
mMatrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
mPath.addRoundRect(dst, mRx, mRy, Direction.CW);
}
@Overridepublicvoiddraw(Canvas canvas) {
canvas.save();
canvas.clipPath(mPath);
canvas.drawBitmap(mBitmap, mMatrix, null);
canvas.restore();
}
@OverridepublicvoidsetAlpha(int alpha) {
}
@OverridepublicvoidsetColorFilter(ColorFilter cf) {
}
@OverridepublicintgetOpacity() {
return PixelFormat.TRANSLUCENT;
}
}
and use it in your Activity:
LinearLayoutll= findViewById(R.id.layout);
Drawabled=newRoundedImageDrawable(getResources(), R.drawable.background, 20, 20);
ll.setBackgroundDrawable(d);
Post a Comment for "Round Border Linerlayout"