2015-06-18 63 views
2

我有一個自定義佈局我grid項目單擊GridView的自定義適配器和佈局

grid.xml

<GridView 
    android:id="@+id/gridview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:verticalSpacing="5dp" 
    android:horizontalSpacing="5dp" 
    android:padding="5dp" 
    android:stretchMode="columnWidth" 
    android:numColumns="2" 
    android:background="@android:color/white" /> 

row_layout.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ProgressBar 
    android:id="@+id/imageLoader" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_weight="2" 
    android:focusable="false" 
    android:focusableInTouchMode="false"/> 
<ImageView 
    android:id="@+id/picture" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:scaleType="centerCrop" /> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_gravity="bottom" 
    android:background="#35000000" 
    android:orientation="vertical"> 
    <HorizontalScrollView 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" 
     android:focusable="false" 
     android:focusableInTouchMode="false"> 
     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="2dp" 
      android:textColor="@android:color/white" 
      android:scrollHorizontally="true" 
      android:maxLines="1" 
      android:textSize="15sp" 
      android:textStyle="bold" /> 
    </HorizontalScrollView> 
    </LinearLayout> 
</FrameLayout> 

現在,當我不有水平滾動視圖點擊事件工作正常,但是當我添加水平滾動視圖時,它不會有任何點擊事件

我知道如果grid佈局有任何可點擊的孩子,則產品Click不會被處理,因此我的問題..

是否可以兼得horizontalscroll和項目的點擊?

謝謝

回答

0

當您單擊項目時,圖像按鈕會佔用焦點。因此請嘗試將android:descendantFocusability =「blocksDescendants」添加到行項目佈局中的佈局中的根元素 - 。它爲我工作。

相關問題