Square shaped layout border with round inside edges

倖福魔咒の 提交于 2019-11-30 09:05:52

From Shape Drawable Doc you can see that shape can't have layer-list inside so you should define your composite_border.xml like this

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/square_border"/>
    <item android:drawable="@drawable/round_border"/>
</layer-list>

note that I changed the order of your items inside the layer-list as stated in the documentation of layer-list
Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top
and you want it to be squared from outside

Issac Balaji

Create a xml file like round_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
   <solid 
       android:color="#CCCC33"/>
   <size 
       android:width="35dp"
        android:height="35dp"/>
</shape>

In the layout set as background

<LinearLayout
    android:id="@+id/layout_wellbeing"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:background="@drawable/rounded_corner_leuvan"
    android:orientation="horizontal" >
</LinearLayout>
benqus

square_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" 
            android:color="#FF000000"
    />
    <solid android:color="#FFC0C0C0" />
</shape>

composite_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <layer-list>
        <item android:drawable="@drawable/round_border"/>
        <!-- <item android:drawable="@drawable/square_border"/> -->
    </layer-list>
</shape>

watch out the comments and the quotation marks! =]

Issac Balaji

Try this will work fine enough:

solid is background color

stroke is border

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
   <solid 
       android:color="@color/white"/>
   <stroke android:width="1dp" android:color="#ffaaaaaa" />
   <size 
       android:width="15dp"
        android:height="15dp"/>
</shape>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!