项目使用自定义适配器和布局

时间:2015-06-18 10:23:56

标签: android android-layout gridview xamarin

我的grid

有自定义布局

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布局有任何可点击的孩子,那么项目点击不会被处理,因此我的问题..

是否可以同时拥有horizontalscroll和项目?

感谢

1 个答案:

答案 0 :(得分:0)

单击项目时,图像按钮会获得焦点。所以尝试添加android:descendantFocusability =&#34; blocksDescendants&#34;布局中的根元素 - 在行项目布局中。它对我有用。

相关问题