[英]Square shaped layout border with round inside edges
我正在嘗試創建一個布局邊框,其角在外面是方形的,在里面是圓形的。 我收集到我需要創建一個由兩種形狀組成的.xml 可繪制定義:一個具有筆划寬度和角半徑,另一個僅具有筆划寬度:
可繪制對象
round_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="4dp" android:color="#FF000000" />
<padding android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
<corners android:radius="4dp" />
<solid android:color="#FFC0C0C0" />
</shape>
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>
當單獨應用時,這些中的每一個都獨立地作為邊界工作,如下所示:
android:background="@drawable/round_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>
和:
android:background="@drawable/composite_border"
布局的背景是完全黑色的,而不僅僅是黑色邊框。
有誰知道如何使圖層列表適用於此任務?
從Shape Drawable Doc中,您可以看到該形狀內部沒有圖層列表,因此您應該像這樣定義您的composite_border.xml
<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>
請注意,我更改了圖層列表中項目的順序,如圖層列表文檔中所述Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top
你想讓它從外面平方
創建一個 xml 文件,如 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>
在設置為背景的布局中
<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>
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>
復合邊框.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>
注意評論和引號! =]
試試這個就足夠了:
solid
是背景色
stroke
是邊界
<?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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.