2011-05-31 51 views
1

我的應用程序基於選項卡式佈局,其中每個選項卡都指定了FragmentActivity。
一個這種活動的具有以下佈置:ListView在後臺接收輸入(Fragment API)

<FrameLayout 
android:id="@+id/filialenView" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<ListView android:layout_height="wrap_content" android:id="@+id/filialList" 
    android:layout_width="fill_parent"></ListView> 

</FrameLayout> 

當切換到該標籤時,將創建的列表和示出。
如果選擇了一個列表項,則創建一個片段,並顯示在列表的頂部:

Filiale fragment = new Filiale(); 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 

    fragmentTransaction.replace(R.id.filialenView, fragment); 

    fragmentTransaction.addToBackStack(null); 
    fragmentTransaction.commit(); 

佈局「filial_detail.xml」爲片段分公司看起來像

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
... content... 
</LinearLayout> 

和在這樣的onCreateView中這樣膨脹

View curView = inflater.inflate(R.layout.filial_detail, container, false); 

一切都像預期的那樣工作,除了在s對片段的虛驚,名單上的可見清單似乎保持了輸入焦點。如果我在某個「空白」區域觸摸屏幕,觸發片段後面的隱藏列表項。另外,如果我滑動,我可以從LogCat輸出中看到該列表滾動。
基於我對FrameLayout的理解,應該可以像這樣堆疊視圖。

該代碼有什麼問題?

由於目前還沒有答案或評論,所以還有一個更一般的問題:
是否有任何已知的情況,即背景中的視圖應該接收輸入,或者在任何情況下都是錯誤的行爲?

回答

1

此行爲的原因是ViewGroups默認不處理輸入事件,但將它們傳遞給它們後面的小部件(如果有)。
在我給出的代碼中,列表的高度爲「wrap_content」,因此剩餘的垂直區域只能通過將輸入傳遞給隱藏片段的LinearLayout元素覆蓋。
我想要的行爲可以通過

  • 設置的ListView爲「FILL_PARENT」 或
  • 添加OnClickListener到的LinearLayout具有空的onClick方法
+0

1爲的高度來實現視圖組的啓示默認情況下不處理輸入事件。 – 2014-07-30 09:18:01