2011-06-28 59 views
7

Tôi đang cố gắng tạo đường viền bố trí với các góc vuông ở bên ngoài và tròn ở bên trong. Tôi đã thu thập được rằng tôi cần phải tạo ra một định nghĩa xml drawable gồm hai hình dạng: một với một bề dày nét và góc radius và khác với chỉ một bề dày nét:Đường viền bố cục hình vuông với các cạnh tròn bên trong

drawables/

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> 

Mỗi tác phẩm independantly như một đường viền khi appliedby tự như vậy:

android: background = "@ drawable/round_border" nhưng khi họ một trong hai hoặc cả hai được thêm vào một drawable mục danh sách như sau:

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> 

và:

android: background = "@ drawable/composite_border"

Nền của bố cục hoàn toàn đen thay vì chỉ là viền đen - bất kỳ ai biết cách làm cho danh sách lớp hoạt động cho tác vụ này?

+0

nhờ để chia sẻ này! – cV2

Trả lời

2

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> 

xem ra những nhận xét và dấu ngoặc kép! =]

+0

Cảm ơn - Tôi đã sửa bài đăng. – jchristof

+0

Cảm ơn - vẫn đang tìm câu trả lời. – jchristof

4

Từ Shape Drawable Doc bạn có thể nhìn thấy hình dạng mà không thể có lớp-list bên trong vì vậy bạn nên xác định composite_border.xml của bạn như

<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> 

ghi chú này mà tôi đã thay đổi thứ tự của các mục của bạn bên trong lớp -list như đã nêu trong tài liệu của lớp-list
Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top
và bạn muốn nó được bình phương từ bên ngoài

0

Hãy thử điều này sẽ làm việc tốt đủ:

solid là màu nền

strokebiên giới

<?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> 
2

tạo một file xml

như 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> 

Trong cách bố trí thiết lập như là nền

<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> 
Các vấn đề liên quan