How can I make a layout with rounded corners? I want to apply rounded corners to my LinearLayout
.
相关问题
- Views base64 encoded blob in HTML with PHP
- How can I create this custom Bottom Navigation on
- Illegal to have multiple roots (start tag in epilo
- How to get the background from multiple images by
- Bottom Navigation View gets Shrink Down
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Creating XML Elements without namespace declaratio
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Get Attribute Value From Simple XML Using JQuery /
Try this...
1.create drawable xml(custom_layout.xml):
2.add your view background
For API 21+, Use Clip Views
Rounded outline clipping was added to the
View
class in API 21. See this training doc or this reference for more info.This in-built feature makes rounded corners very easy to implement. It works on any view or layout and supports proper clipping.
Here's What To Do:
android:background="@drawable/round_outline"
android:clipToOutline="true"
Unfortunately, there seems to be a bug and this XML attribute currently is not recognized. Luckily, we can set the clipping in Java:
View.setClipToOutline(true)
What It Looks Like:
Special Note About ImageViews
setClipToOutline()
only works when the View's background is set to a shape drawable. If this background shape exists, View treats the background's outline as the borders for clipping and shadowing purposes.This means that if you want to round the corners on an ImageView with
setClipToOutline()
, your image must come fromandroid:src
instead ofandroid:background
(since background is used for the rounded shape). If you MUST use background to set your image instead of src, you can use this nested views workaround:A better way to do it would be:
background_activity.xml
This will work below API 21 also, and give you something like this:
If you are willing to make a little more effort more better control, then use
android.support.v7.widget.CardView
with itscardCornerRadius
attribute (and setelevation
attribute to0dp
to get rid of any accompanying drop shadow with the cardView). Also, this will work from API level as low as 15.Intead of xml
use (in code):
The best and simplest method would be to make use of card_background drawable in your layout. This also follows Google's material design guidelines. Just include this in you LinearLayout:
Add this to your drawable directory and name it card_background.xml:
Here's a copy of a XML file to create a drawable with a white background, black border and rounded corners:
save it as a xml file in the drawable directory, Use it like you would use any drawable background(icon or resource file) using its resource name (R.drawable.your_xml_name)