2011-03-11 54 views
0

我實現了一個自定義列表視圖,但是現在沒有視覺反饋表明一個元素已被選中。我認爲這是微不足道的,但我找不到任何東西 - 任何人都可以提供關於如何將默認的UI元素聚焦行爲應用到我的列表視圖項目的提示?如何指示列表視圖項目焦點?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusableInTouchMode="true"> 


    <TextView android:id="@+id/list_item" 
     android:layout_gravity="center_vertical" 
     android:layout_width="0dip" 
     android:layout_weight="1.0" 
     android:textSize="20sp" 
     android:textColor="#FFFFFFFF" 
     android:layout_height="wrap_content" 
     android:padding="20dp"/> 


</LinearLayout> 

從什麼樣的回答我到目前爲止得到了,我想我要澄清我想要做的事:我想模仿一個ListView項做的行爲(在標準UI)長時按下。當你匆匆穿過它時,它並沒有真正做任何事情,但是一旦觸及該物品並隨時保持它,它就會變成顏色[以我的橙色爲例],然後快速轉變爲白色。

而且,經過進一步檢查,我認爲這可能會發生只有當添加一個上下文菜單 - 我會試試看,並與結果編輯。

+0

你可以發佈該XML文件? – 2011-03-11 05:25:44

+0

我想要那個包含listview的xml文件。 – 2011-03-11 05:32:38

+0

沒有。這是一個基於API演示的自定義ListView:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html – 2011-03-11 05:35:14

回答

1

要做到這一點的方法是添加一個上下文菜單。這將帶來我想要的效果。

0

你可以嘗試設置一個選擇器drawable你的listview行背景。

android:background="@drawable/listview_bg" 

提拉需要是這樣的:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="true" android:drawable="@drawable/list_bg_blue"/> 
<item android:state_pressed="true" android:state_enabled="false" android:drawable="@drawable/list_bg_blue"/> 
<item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/list_bg_blue"/>  
<item android:state_enabled="false" android:drawable="@drawable/list_bg_blue"/>  
<item android:drawable="@drawable/list_bg_grey"/> 

此外,嘗試RelativeLayout的,而不是LinearLayout中。

相關問題