How can I create a border around an Android LinearLayout? - android

I have one big layout, and one smaller layout inside of it.
How do I create a line border around the small layout?

Sure. You can add a border to any layout you want. Basically, you need to create a custom drawable and add it as a background to your layout. example:
Create a file called customborder.xml in your drawable folder:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<stroke android:width="1dp" android:color="#CCCCCC"/>
</shape>
Now apply it as a background to your smaller layout:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/customborder">
That should do the trick.
Also see:
http://tekeye.biz/2012/add-a-border-to-an-android-layout
How to add border around linear layout except at the bottom?

Creat XML called border.xml in drawable folder as below :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
then add this to linear layout as backgound as this:
android:background="#drawable/border"

Try this:
For example, let's define res/drawable/my_custom_background.xml as:
(create this layout in your drawable folder) layout_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="2dp" android:height="2dp"
android:color="#FF0000" />
<solid android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
<corners android:radius="1dp" android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
</layer-list>
main.xml
<LinearLayout
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/layout_border" />
</LinearLayout>

Create a one xml file in drawable folder
<stroke
android:width="2dp"
android:color="#B40404" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="4dp" />
Now call this xml to your small layout background
android:background="#drawable/yourxml"

This solution will only add the border, the body of the LinearLayout will be transparent.
First, Create this border drawable in the drawable folder, border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#ec0606"/>
<corners android:radius="10dp"/>
</shape>
Then, in your LinearLayout View, add the border.xml as the background like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/border">

you can do it Pragmatically also
GradientDrawable gradientDrawable=new GradientDrawable();
gradientDrawable.setStroke(4,getResources().getColor(R.color.line_Input));
Then set the background of layout as :
LinearLayout layout = (LinearLayout ) findViewById(R.id.ayout); layout .setBackground(gradientDrawable);

I'll add Android docs link to other answers.
https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
It describes all attributes of the Shape Drawable and stroke among them to set the border.
Example:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#F00"/>
<solid android:color="#0000"/>
</shape>
Red border with transparent background.

Don't want to create a drawable resource?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:minHeight="128dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="#android:color/white">
<TextView ... />
</FrameLayout>
</FrameLayout>

Try This in your res/drawable
<?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<padding android:left="15dp"
android:right="15dp"
android:top="15dp"
android:bottom="15dp"/>
<stroke android:width="10dp"
android:color="#color/colorPrimary"/>
</shape>
</item><item android:left="-5dp"
android:right="-5dp"
android:top="-5dp"
android:bottom="-5dp">
<shape android:shape="rectangle">
<solid android:color="#color/background" />
</shape></item></layer-list>

Nobody seems to be using the method we came up with so I thought I would share, as it involves much simpler code.
Simply nest one layout inside another with padding, and the outer one can be colored, making a frame.
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/llSignatureBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/black"
android:orientation="vertical"
android:padding="4dp">
<com.yourmom.mobiledriverapp.Controls.SignatureArea
android:id="#+id/signatureArea"
android:layout_width="#dimen/signaturearea_width"
android:layout_height="#dimen/signaturearea_height"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp" />
</androidx.appcompat.widget.LinearLayoutCompat>

Related

How to create a shadow border inside a LinearLayout or EditText in android?

How to add a shadow border on 4 sides of an edit text as shown in the image? Applied below code but it creates a shadow on single side only.
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFBDBDBD"
android:centerColor="#65FFFFFF"
android:endColor="#00FFFFFF"
/>
<stroke
android:width="1dp"
android:color="#C3C3C3" />
<corners
android:radius="5dp" />
</shape>
You can use elevation like :-
android:elevation="5dp"
elevation worked as Z-index.
You can try adding width and color inside the shape tag.
It will look like this:
<stroke android:width="3dp" android:color="#bfafb2"/>
First create this background drawable with a rectangle, round corner and a stroke in grey. Called background_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"/>
<corners android:radius="5dp" />
<stroke android:width="1dp"
android:color="#C3C3C3"/>
</shape>
After that you set this as android:background="" in your LinearLayout and EditText, both widgets have android:elevation="2dp" for it's shadow on each sites matching the stroke of the rectangle. Here is your layout called activity_main.xml:
<LinearLayout
android:layout_width="200dp"
android:layout_height="100dp"
android:elevation="2dp"
android:id="#+id/linear_layout"
android:background="#drawable/background_drawable"
android:layout_centerInParent="true"
android:orientation="horizontal" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/edit_text"
android:elevation="2dp"
android:layout_marginTop="10dp"
android:background="#drawable/background_drawable"
android:layout_below="#+id/linear_layout"
android:layout_centerHorizontal="true"
android:padding="10dp"/>
The final result will look like this image.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>

Custom shaped Linearlayout with curved side in android

I am trying to make a custom shaped linearlayout like below
I am trying to make only one side curved. Tried with corner radius but it doesn't give the same look as above.
Already tried this background shape as below :-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#3F51B5" />
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<corners
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
it rounds only corners and on increasing the value shape is not preserved it gets too circular. I WANT CURVED line and not rounded corners
Its very late already but this is for future seekers.
I think vector drawables are the most perfect solution for this. Use below vector as background to get custom shaped bottom curved layout.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="100.0"
android:viewportWidth="200.0">
<path
android:fillColor="#YOUR_FAVORITE_COLOR"
android:pathData="M200,0H0v4.5h0v75.8h0c17.8,10.2 56,17.2 100.5,17.2c44.5,0 81.6,-7 99.5,-17.2h0V4.5h0V0z" />
Create a shape file in drawable folder e.g: my_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<stroke
android:width="0.5dp"
android:color="#color/theme_red" />
<solid android:color="#color/white" />
</shape>
then add this shape in your layout as a background. e.g:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/my_shape"
android:orientation="horizontal">
</LinearLayout>
shape_curve.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" />
</item>
<item
android:bottom="0dp"
android:left="-100dp"
android:right="-100dp"
android:top="-80dp">
<shape android:shape="oval">
<solid android:color="#color/colorAccent" />
</shape>
</item>
</layer-list>
Use
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#drawable/shape_curve"
android:orientation="horizontal" />
what i did is
create a drawable allowaccess_button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
</selector>
Try below layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#fefefe"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="110dp">
</RelativeLayout>
<ImageView
android:layout_marginTop="85dp"
android:src="#drawable/allowaccess_button_normal"
android:layout_width="match_parent"
android:layout_height="50dp" />
</RelativeLayout>
<layer-lisxmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="175dp">
<shape android:shape="oval">
<gradient
android:angle="135"
android:startColor="#f56f2c"
android:endColor="#fa9f46"/>
</shape>
</item>
<item android:bottom="40dp">
<shape android:shape="rectangle">
<gradient
android:angle="135"
android:startColor="#f56f2c"
android:endColor="#fa9f46"/>
</shape>
</item>
</layer-list>
you can set the dimension in the value -dimension.xml fime and then set it in your xml of your linearlayout it will give the following like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFF00" />
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
just make a xml file in your drawable set the dimensio u need and then call it by your linear layout

How can I set the width and colour of all the borders of EditText?

I have EditText. How can I set its border width and colour only and in xml? I can't figure it out and all I've found so far didn't explain that in a simple way. But I believe that so such a simple thing there must be a simple way to do it.
Create a drawable xml for your EditText with named EditTextStyle.xml in your Drawable Folder like below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
Change your color and width according to your requirement and add this as the background of your EditText of your Layout xml
android:background="#drawable/EditTextStyle"
You can create Customize editText xml in Drawable folder like
custom_edttext.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#641E1E" />
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
/>
</shape>
and use custom_edittext.xml as background of editText
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/custom_edittext"/>
I don't have enough karma to say this as a comment. So typing as answer. See this link. Just create an xml file in drawable(here rounded_edittext.xml in the example) and set background for the EditText as
android:background="#drawable/rounded_edittext"
The <stroke> in the rounded_edittext.xml is used to set the thickness and color of the border of the EditText.
Here's the rounded_edittext.xml as shown in the link.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#2f6699" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp" android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp" />
</shape>
I hope this answer match with your needs.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#76b385" />
<corners android:radius="12dp" />
</shape>
</item>
<item
android:bottom="5dp"
android:left="1dp"
android:right="1dp">
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:centerColor="#ffffff"
android:centerX="50%"
android:endColor="#ffffff"
android:startColor="#ededed"
android:type="linear" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
Modify this xml with your needs.
put this file in your drawable folder
edit_text_back.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#641E1E" />
<corners
android:radius="5dp" />
</shape>
and add use this drawable as background to your edittext as
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/edit_text_back"/>
If you need any assistance.Please let me know and mark this answer up.if it helps.Happy coding :)

Rounded corner for textview in android

I have a textview and want its corner to be in round shape. I already know it can be done using android:background="#drawable/somefile". In my case, this tag is already included so cannot use again. e.g android:background="#drawable/mydialogbox" is already there to create image in background
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#drawable/mydialogbox"
android:orientation="horizontal" >
<TextView
android:id="#+id/textview_name"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</RelativeLayout>
so when I want textview(textview_name) also with round corner, how this can be achieved.
Create rounded_corner.xml in the drawable folder and add the following content,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#color/common_border_color" />
<solid android:color="#ffffff" />
<padding
android:left="1dp"
android:right="1dp"
android:bottom="1dp"
android:top="1dp" />
<corners android:radius="5dp" />
</shape>
Set this drawable in the TextView background property like so:
android:background="#drawable/rounded_corner"
I hope this is useful for you.
Beside radius, there are some property to round corner like topRightRadius, topLeftRadius, bottomRightRadius, bottomLeftRadius
Example TextView with red border with corner and gray background
bg_rounded.xml (in the drawables folder)
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="10dp"
android:color="#f00" />
<solid android:color="#aaa" />
<corners
android:radius="5dp"
android:topRightRadius="100dp" />
</shape>
TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_rounded"
android:text="Text"
android:padding="20dp"
android:layout_margin="10dp"
/>
Result
With the Material Components Library you can use the MaterialShapeDrawable.
With a TextView:
<TextView
android:id="#+id/textview"
../>
You can programmatically apply a MaterialShapeDrawable:
float radius = getResources().getDimension(R.dimen.corner_radius);
TextView textView = findViewById(R.id.textview);
ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED,radius)
.build();
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
ViewCompat.setBackground(textView,shapeDrawable);
If you want to change the background color and the border just apply:
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,R.color.....));
shapeDrawable.setStroke(2.0f, ContextCompat.getColor(this,R.color....));
Since your top level view already has android:background property set, you can use a <layer-list> (link) to create a new XML drawable that combines both your old background and your new rounded corners background.
Each <item> element in the list is drawn over the next, so the last item in the list is the one that ends up on top.
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap android:src="#drawable/mydialogbox" />
</item>
<item>
<shape>
<stroke
android:width="1dp"
android:color="#color/common_border_color" />
<solid android:color="#ffffff" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
There is Two steps
1) Create this file in your drawable folder :- rounded_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" /> // set radius of corner
<stroke android:width="2dp" android:color="#ff3478" /> // set color and width of border
<solid android:color="#FFFFFF" /> // inner bgcolor
</shape>
2) Set this file into your TextView as background property.
android:background="#drawable/rounded_corner"
You can use this drawable in Button or Edittext also
create an xml gradient.xml file under drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="50dip" />
<stroke android:width="1dip" android:color="#667162" />
<gradient android:angle="-90" android:startColor="#ffffff" android:endColor="#ffffff" />
</shape>
</item>
</selector>
then add this to your TextView
android:background="#drawable/gradient"
You can use the provided rectangle shape (without a gradient, unless you want one) as follows:
In drawable/rounded_rectangle.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<stroke android:width="1dp" android:color="#ff0000" />
<solid android:color="#00ff00" />
</shape>
Then in your text view:
android:background="#drawable/rounded_rectangle"
Of course, you will want to customize the dimensions and colors.
Right Click on Drawable Folder and Create new File
Name the file according to you and add the extension as .xml.
Add the following code in the file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<stroke android:width="1dp" />
<solid android:color="#1e90ff" />
</shape>
Add the line where you want the rounded edge android:background="#drawable/corner"
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="5dp" />
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
Put your TextView inside MaterialCardView:
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="25dp"
>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/emergency_sms_template"
android:padding="6dp"
android:textSize="11sp"
/>
</com.google.android.material.card.MaterialCardView>
You can use SVG for rounding corners and load into an ImageView and use ConstraintLayout to bring ImageView on TextView
I used it for rounded ImageView and rounded TextView
Simply using an rounded corner image as the background of that view
And don't forget to have your custom image in drawable folder
android:background="#drawable/my_custom_image"

how to make a rounded corners for an image in image view using XML layout in android

I have tried many times but i know that i am missing something,could you Guys please explain it..
Following is what, i have tried
<ImageView
android:id="#+id/Dicimage"
android:layout_width="130px"
android:layout_height="100px"
android:src="#drawable/slang"
android:background="#drawable/corner"
android:padding="1dp"/>
Created Corner XML in resource folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<stroke android:width="0dp"
android:color="#ff000000"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:radius="30px"/>
</shape>
What i am getting is, the border is only rounded rectangle but the image is still rectangle in shape
No, that is not possible. You have to do it programmatically.
What you are doing is create rounded corners background and draw the drawable over it.
Here's the great article of how to create rounded corners image from Romain Guy: http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
you can add your ImageView in a CardView with attribute cardElevation=0
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thumbnail_card"
card_view:cardCornerRadius="15dp"
card_view:cardElevation="0dp"
android:layout_margin="10dp">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="110dp"
android:layout_height="75dp"
android:scaleType="centerCrop" />
</android.support.v7.widget.CardView>
TRy this :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:radius="30px"/>
</shape>
Taken from this Post : Android ImageView with Rounded Corners not working
Use that xml file as foreground
I mean, instead of
android:background="#drawable/corner"
Use this
android:foreground="#drawable/corner"
You should add this code as some_foreground.xml to drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="8dp"
android:color="#color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="#dimen/padding_margin_8" />
<stroke
android:width="8dp"
android:color="#color/white" />
</shape>
</item>
</layer-list>
And then you can use this as foreground for your ImageView.
You should add this like:
<ImageView
android:id="#+id/event_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="#drawable/some_foreground"
android:scaleType="centerCrop"
android:src="#drawable/your_image" />
Here's a super late answer but if you're trying to create a circular ImageView:
Create a drawable in drawable folder called circle:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#android:color/black"/>
<size
android:height="60dp"
android:width="60dp"/>
</shape>
ImageView:
<ImageView
android:id="#+id/Dicimage"
android:layout_width="130px"
android:layout_height="100px"
android:src="#drawable/slang"
android:background="#drawable/circle"
android:padding="1dp"/>

Categories

Resources