2012-03-04 25 views
1

這兩個屬性都是以編程方式設置的。我嘗試重新啓動,當設置TextView背景時更改AVD - bu - 文本消失。是的,它有不同的顏色,然後背景。沒有背景文字是可見的。我不知道問題出在哪裏?在Android中設置TextView背景時消除文本

{此代碼如下工作正常}

 <TextView 
      android:id="@+id/txt_Number" 
      android:layout_width="match_parent" 
      android:layout_height="25dp" 
      android:gravity="center" 
      android:text="1" 
      android:textColor="@color/red" 
      android:textSize="10sp" 
      android:textStyle="bold" /> 

下面這段代碼只顯示背景,沒有文字:/

<TextView 
      android:id="@+id/txt_Number" 
      android:layout_width="match_parent" 
      android:layout_height="25dp" 
      android:gravity="center" 
      android:text="1" 
      android:background="@drawable/txtbg" 
      android:textColor="@color/red" 
      android:textSize="10sp" 
      android:textStyle="bold" /> 

圖像採用透明背景的png格式。 TextView位於TableLayout的TableRow中。此佈局是ListView項目的一部分 - 但我不認爲這是問題。

隨着背景:

enter image description here

無背景:

enter image description here

事實上,有2個TextViews,一個表示距離和第二號碼 - 第一個沒有背景。當我嘗試爲第二個背景添加背景時 - 兩個文本都消失了。

+0

嘗試使用機器人:layout_height =「WRAP_CONTENT」。然後嘗試 – 2012-03-04 14:07:03

+0

仍然無法正常工作 – Darko 2012-03-04 14:09:07

+0

然後更改安卓重力=「CENTER_HORIZONTAL」,並嘗試 – 2012-03-04 14:16:35

回答

0

我面臨同樣的問題。經過一番研究後,我仍然不知道提供這種情況的理由。爲了解決這個問題,我只需在TextView下面放置一個具有理想背景的View。不漂亮,但工程。