I have created a round corner drawable resource round_corner_bg.xml
:
我创建了一个圆角可绘制资源round_corner_bg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
I applied it to my LinearLayout
:
我将它应用于我的LinearLayout:
<LinearLayout ...>
android:background="@drawable/round_corner_bg"
...
It works fine. However, it rounded all four corners, how can I make it to only round the top left and top right corner?
它工作正常。然而,它四舍五入所有角落,我怎样才能使它只围绕左上角和右上角?
5 个解决方案
#1
2
Try this
尝试这个
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke
android:width="3dp"
android:color="#B1BCBE" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
OUTPUT
OUTPUT
#2
1
You can use the corner tag as shown below
您可以使用角标记,如下所示
<corners android:topLeftRadius="10dip" android:topRightRadius="10dip"/>
#3
1
Change the following:
更改以下内容:
<corners android:radius="10dp" />
To:
至:
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
#4
0
You can use like this:
你可以像这样使用:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- you can use any color you want -->
<solid android:color="@color/colorPrimary" />
<corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<stroke android:width="0.6dp" android:color="@color/white" />
</shape>
</item>
</selector>
#5
0
Just replace
只需更换
<corners android:radius="10dp"/>
with
同
<corners android:topRightRadius="10dp" android:topLeftRadius="10dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" />
Change value as per side you want
根据需要更改值
#1
2
Try this
尝试这个
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke
android:width="3dp"
android:color="#B1BCBE" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
OUTPUT
OUTPUT
#2
1
You can use the corner tag as shown below
您可以使用角标记,如下所示
<corners android:topLeftRadius="10dip" android:topRightRadius="10dip"/>
#3
1
Change the following:
更改以下内容:
<corners android:radius="10dp" />
To:
至:
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
#4
0
You can use like this:
你可以像这样使用:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- you can use any color you want -->
<solid android:color="@color/colorPrimary" />
<corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<stroke android:width="0.6dp" android:color="@color/white" />
</shape>
</item>
</selector>
#5
0
Just replace
只需更换
<corners android:radius="10dp"/>
with
同
<corners android:topRightRadius="10dp" android:topLeftRadius="10dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" />
Change value as per side you want
根据需要更改值