2013-06-26 32 views
0

我有LinearLayout背景是選擇器。 在此佈局中,有其他ViewsImageViewLinearLayout有兩個TextView,但不顯示此TextViews。 這裏是layout xml文件:帶背景的LinearLayout不顯示小孩的所有視圖

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:background="@drawable/category_item" 
    android:padding="6dip" > 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_marginRight="6dip" 
    android:contentDescription="@string/logo" /> 

<LinearLayout 
    android:layout_width="0dip" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/toptext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center_vertical" /> 

    <TextView 
     android:id="@+id/bottomtext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" /> 
</LinearLayout> 


</LinearLayout> 

,這裏是選擇代碼:

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

    <item android:drawable="@drawable/category_clicked" android:state_focused="true"/> 
    <item android:drawable="@drawable/category_norm"/> 

</selector> 
+0

所以所有的答案都是錯誤的?如果不接受一個.. –

回答

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:background="@drawable/category_item" 
    android:orientation="vertical" 
    android:padding="6dip" > 

機器人:方向= 「垂直」 可能缺失

+0

添加,但沒有任何改變。我有問題,只能查看'TextBox' textes – pepela

+0

嘗試設置textviews的高度以填充父母以及 –

0
android:layout_weight="1" 

要麼刪除這來自所有的小部件。或者在所有的孩子中使用..(imageView,內部線性佈局,兩個文本視圖)

+0

刪除它,但佈局剛剛變得更高,將'layout_width'更改爲'wrap_content'它現在有很好的高度,但文本仍然丟失 – pepela

+0

也在imageview android:layout_height =「fill_parent」...使用wrap_content – stinepike

+0

@StinePike,你可以解釋爲什麼重量應該被添加到所有小部件? –

1

我試過這種佈局,它顯示您的文本視圖。也許你設置的文字是空的。只要檢查一下。

,從這裏刪除此android:layout_weight="1"

<TextView 
    android:id="@+id/toptext" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center_vertical" /> 

其useles。

+0

刪除,但沒有什麼我在'listView'中使用此佈局作爲項目,並且它在設置背景(選擇器)後開始不工作,並且如果背景只是圖像它僅在單擊佈局時顯示文本 – pepela

+0

您需要更改文本顏色。我認爲只是強加了。 –

+0

不用顏色可以改變它,什麼也沒發生 – pepela