This question already has answers here:
How do I create a ListView with rounded corners in Android?
(11 answers)
Closed 2 years ago.
I have this View in Kotlin:
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/colorPrimary"
/>
and I need to round the corners since it is a Dot and I have been investigating and testing how I can do it to round the corners but I just can't find the answer.
How can I solve it?
you have to create a drawable shape xml file and set background property of the view to the drawable file!
res/drawable/circle.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#color/colorPrimary" />
</shape>
res/drawable/rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/colorPrimary"/>
<corners android:radius="5dp" />
</shape>
and set background to view like this :
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#drawable/rounded"
/>
Related
I am trying to add a linear layout with rounded corners and blurred background in my app. So far ive managed to give the layout rounded corners but i cant figure out how to give it a blurred background.Ive tried setting an alpha attribute in the xml file but it dosent work.
Heres what i want to achieve:
The Drawable resource file:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff"/>
<stroke android:width="0.5dp" android:color="#B1BCBE" />
<corners android:radius="160dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
The Xml code of the layout:
<LinearLayout
android:id="#+id/team_lay"
android:layout_width="match_parent"
android:layout_height="95dp"
android:layout_marginTop="40dp"
android:background="#drawable/layout_bg"
android:orientation="horizontal">
</LinearLayout>
What i have achieved so far:
How can i achieve the desired results?
TIA..!!!
You can achieve it by create a blur background as a xml file and then set background of your container view to it.
Try my example:
blur_background.xml
<?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="#4CAF50" />
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<solid android:color="#AA000000" />
</shape>
</item>
</layer-list>
And your container layout:
<LinearLayout
android:id="#+id/team_lay"
android:layout_width="match_parent"
android:layout_height="95dp"
android:layout_marginTop="40dp"
android:background="#drawable/blur_background"
android:orientation="horizontal">
</LinearLayout>
Hope it help. ^^
So i fount the solution myself. I changed the transparency of the solid color in the drawable resouce file(as mentioned here https://stackoverflow.com/a/41865518/8175719 ) and it worked.
This question already has answers here:
How to make an ImageView with rounded corners?
(58 answers)
Closed 4 years ago.
I have created the layout with Imageview and I have set custom background with corner radius, the parent layout is cornered but the Imageview is not rounded cornered. How can I achieve this?
Thanks in advance.
bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="#color/list_item_bg"/>
<stroke
android:width="2dp"
android:color="#color/colorAccent" />
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_item_bg"
>
<ImageView
android:id="#+id/food_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:scaleType="centerCrop"
android:clipToOutline="true"
android:background="#drawable/image_bg"
android:src="#drawable/sample_image"/>
</LinearLayout>
Create res/drawable/round_outline.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
Set the drawable as your ImageView's background
android:background="#drawable/round_outline"
On ImageView (layout)
android:clipToOutline="true"
This question already has answers here:
How to make an ImageView with rounded corners?
(58 answers)
Closed 5 years ago.
Im using Picasso and trying to put image in circle imageview, but the picture is still square. How can i fix it ?
Picasso.with(context).load(resId).resizeDimen(R.dimen.image_size, R.dimen.image_size).into(holder.mImageViewItem);
image_size = 60dp
drawable resource :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFF"/>
and imageview :
<ImageView
android:id="#+id/picture_imageview_item"
android:layout_marginTop="15dp"
android:layout_marginLeft="25dp"
android:layout_marginBottom="15dp"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#drawable/buttonshape" />
There are different libraries you can use for a circle shaped image. The best one which i came across is
Siyamed
You can make a simple circle with white border and transparent content with shape.
// res/drawable/circle.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
android:useLevel="false" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="10dp"
android:color="#android:color/white" />
</shape>
Then make a layerlist drawable and put it as background to your imageview.
// res/drawable/img.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/ic_launcher"/>
<item android:drawable="#drawable/circle"/>
</layer-list>
and put it as background to your imageview.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/img"/>
In place of ic_launcher, you can add your image.
Thanks !!
This question already has answers here:
How to make a round button?
(23 answers)
Closed 6 years ago.
I want to create button login and sign up like
.
Include the button.xml in your layout and use it as a button by giving it an id or u can set the border to button too in order to get the same result
button.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border">
<TextView android:id="#+id/skillTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cleaner"
android:textSize="#dimen/abc_text_size_medium_material"
android:textColor="#color/text_grey"
android:layout_margin="#dimen/normal_margin"
android:layout_centerInParent="true"
/>
</RelativeLayout>
drawable/border.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="#color/white" />
</shape>
This question already has answers here:
Android - border for button
(11 answers)
Closed 2 years ago.
Hi I'm covering my ImageView in buttons but while they are so close to each other you cant make out that it is buttons, its just a big red square. I need a quick and easy way to give my buttons borders/edges or something so you can see the different buttons.
Create a Shape in Drawable Resource
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#C0213A" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
</shape>
In your XML
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="#drawable/your_shape"> `<!--This is your shape created--`>
There is no border for buttons but you can use shape to make a drawable with border then put it as background for the button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/red" />
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>