【问题标题】:Item Click on Gridview with custom adapter and layout项目单击带有自定义适配器和布局的 Gridview
【发布时间】:2015-06-18 10:23:55
【问题描述】:

我的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 和项目??

谢谢

【问题讨论】:

    标签: android android-layout gridview xamarin


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      相关资源
      最近更新 更多