![](/img/trans.png)
[英]why cannot i see a textView above another view in relative layout?
[英]Cannot see View after changing background of TextView
好的,我有一個ListView
項的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/draweritemtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:fontFamily="sans-serif-thin"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#111"
android:textSize="20sp" />
<View
android:id="@+id/separator"
android:layout_width="fill_parent"
android:layout_height="0.2dp"
android:background="@android:color/darker_gray"
android:visibility="visible" />
</LinearLayout>
因此,使用此設置,一切正常。 它顯示如下:
ITEM
-------
ITEM
-------
ITEM
-------
但我不想從Android中選擇藍色,因此我想通過將textviews背景更改為@drawable/drawer_active_selector
來更改@drawable/drawer_active_selector
。 這是我的選擇器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@drawable/notquiteverylightgray" />
<item android:drawable="@drawable/white" />
</selector>
還有我的繪畫
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="semitransparent_white">#77ffffff</drawable>
<drawable name="verylightgray">#eee</drawable>
<drawable name="notquiteverylightgray">#ddd</drawable>
<drawable name="white">#fff</drawable>
</resources>
現在看起來像這樣:
ITEM
ITEM
ITEM
------
填充是正確的,但是我想念的是分隔符( <View />
)
我該如何找回他們?
您的解決方案中有兩個錯誤。 默認情況下, ListView
的項目單擊由ListView
本身處理,而不由所單擊的子視圖處理。 因此, @drawable/drawer_active_selector
將TextView
的背景更改為@drawable/drawer_active_selector
使用android:listSelector
xml屬性或List.setSelector()
方法之一來設置ListView
的項目選擇器drawable。 另一個錯誤涉及分隔線。 您的解決方案不必要地冗長。 有一種添加分隔線的簡便方法。 只需使用ListView
的android:divider
屬性或ListView.setDivider()
方法即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.