2015-02-24 39 views
0

這是我的繪製代碼:機器人 - 爲什麼自定義繪製不影響TextView的

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

    <corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 

    <solid android:color="#3C1251" /> 
</shape> 

這就是所謂的haraj.xml在我的繪製文件夾中的XML文件。

這是我的XML佈局:

<TextView 
     android:id="@+id/harajamount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:gravity="center" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="15dp" 
     android:textColor="#fff" 
     android:textSize="15sp" 
     android:padding="8dp" 
     android:background="@drawable/haraj" 
     android:text="2500" 
     /> 

奇怪的是它沒有影響的TextView。我得到沒有背景顏色和沒有角落的textview。

我在做什麼錯?

+0

將此文本視圖置於任何類型的佈局中並設置背景爲那個佈局。 – iffu 2015-02-24 07:38:39

+0

@iffu沒有工作,我試過了 – 2015-02-24 08:12:29

+0

好吧等待我現在工作,並給你的解決方案 – iffu 2015-02-24 08:14:17

回答

0

你現在的背景是什麼?希望它不會是#3C1251。因爲我只是試着用你的代碼。它的工作非常完美,併爲textview提供了適當的背景顏色。

enter image description here

希望你可能會得到任何幫助。讓我知道,如果它不工作...

享受編碼... :)

+0

謝謝你的回覆,沒有背景顏色是不一樣的,主要佈局的背景是白色的.still不顯示:( – 2015-02-24 07:58:18

+0

可以你請與我分享你的Java代碼?你做錯了什麼。 – 2015-02-24 09:09:39

0

試試這個

<corners android:radius="7dp"/> 

代替

<corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 
0

試試這個

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

    <corners android:radius="10dp" /> 

    <solid android:color="#3C1251" /> 

    <size android:height="23dp" /> 

</shape> 
相關問題