2012-02-13 13 views
30

tôi vừa tạo ra một vòng tròn màu đỏ sử dụng hình dạng android:Làm cách nào để đặt hình nền của tôi trong xml?

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:innerRadiusRatio="4" 
    android:shape="ring" 
    android:thicknessRatio="9" 
    android:useLevel="false" > 

    <solid android:color="#FF0000" /> 

    <size 
     android:height="48dip" 
     android:width="48dip" /> 

</shape> 

Điều này thực sự thú vị nhưng tôi không thể thiết lập màu nền của vòng tròn màu sắc của tôi. Tôi đã thử android:background="#FFFFFF" nhưng nó luôn xuất hiện màu đen trong bố cục của tôi. Làm thế nào tôi có thể thiết lập nền của hình dạng trên?

Trả lời

56

Tôi nghĩ rằng một layer-list có thể giúp bạn:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item> 
     <shape android:shape="rectangle" > 
      <solid android:color="#ffffff" /> 
     </shape> 
    </item> 
    <item> 
     <shape 
      android:innerRadiusRatio="4" 
      android:shape="ring" 
      android:thicknessRatio="9" 
      android:useLevel="false" > 
      <solid android:color="#FF0000" /> 
      <size 
       android:height="48dip" 
       android:width="48dip" /> 
     </shape> 
    </item> 

</layer-list> 
0

Ok, làm thế nào về điều này?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF"> 
<TextView android:text="Foo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#000000" 
    android:gravity="center" 
    android:background="@drawable/red_circle"/> 
    </LinearLayout> 


</LinearLayout> 
+0

tôi sử dụng một TextView, không may, tôi cần phải đặt văn bản bên –

+1

Tôi chỉ posted an update rằng loại công trình, nhưng vòng tròn bị cắt không may trên cùng và dưới cùng. Tôi sẽ phải chơi nhiều hơn một chút để mở rộng hoàn toàn. – Kaediil