2014-02-14 35 views
0

我有一個ListView這裏OnItemClick不工作是其行佈局如果滾動型的佈局

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="280dp"> 
<ScrollView 
    android:scrollbars="none" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/exploreImage" 
     android:src="@drawable/beard1" 
     android:adjustViewBounds="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</ScrollView> 
<TextView 
    android:id="@+id/exploreText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 

我在我的佈局來實現滾動型,說明here

所以,我的麻煩是OnItemClickListener,我設置爲listView不起作用。我可以實現OnTouchListener,但在這種情況下,我需要知道點擊項目的位置和ID。

UPD1:我的listView的代碼。 這

<ListView 
    android:id="@+id/exploreList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

UPD2:我不需要這個滾動滾動型,只有ListView控件。另外我想讓OnItemClickListener工作。

任何想法? 謝謝。

+1

你在哪裏有你的listview?我沒有看到一個列表視圖! – WarrenFaith

+0

@WarrenFaith我展示了我的行layot的代碼,我的ListView代碼的代碼會幫助嗎? Oo –

+0

假設你想檢測列表中被點擊的項目爲什麼不使用onListItemClick?如果你不想檢測被點擊的列表項,那麼我不明白你的問題。 – pedromss

回答

0

那麼,我已經研究了評論和aswers並試圖實現其他解決方案。在這裏,我發現了。

要求是 - 將圖像綁定到View的頂部和兩側,並在底部裁剪它。但是這個視圖像ListView中的item一樣實現,所以我必須將所有焦點和偵聽器保存在ListView中。

因爲ScrollView破壞了焦點和偵聽器,所以無法實現。

裁剪圖像programmaticaly需要大量的時間在大圖片的情況下。它也不能實施。

我決定這樣做的方式是覆蓋ImageView中的onMeasure方法,如topic中所述。

我希望這對任何人都有幫助。

0

問題是:您的ScrollView。

我們可以給出的基本答案:找到另一種方式,以您想要的方式在行內顯示圖像。基本上只是搜索如何裁剪圖像和裁剪,以便它適合。

未經測試的代碼即可裁剪圖片:

Bitmap croppedBitmap = Bitmap.createBitmap(bitmapOriginal, destWidth, destHeight, bitmapOptions); 

一些替代方法,可以在Bitmap文檔中找到。