通过两次触摸而不是一次在列表视图中滚动

时间:2015-10-25 20:46:25

标签: android listview

我的Scroll ListView有问题。 它太奇怪了,滚动只能用两个手指而不是一个手指。 看起来第一次触摸是选择ListView,第二次触摸是滚动。

在布局上有editText,它最初是在启动活动时的焦点。我改变了它,但无论如何滚动都不起作用。

可能需要在代码中设置ListView的焦点吗?

我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"

    android:background="#eeeeee"

    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/relativeLayout2"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#ffffff">
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/searchEditText"

        android:drawableLeft="@mipmap/search_icon"
        android:layout_alignParentTop="true"
        android:layout_marginTop="0dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:imeOptions="actionSearch"
        android:singleLine="true"

        />

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/radiogroup"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_below="@+id/searchEditText">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Событие"
            android:id="@+id/radioButton"


            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Место"
            android:id="@+id/radioButton2"
            android:layout_marginLeft="18dp"
            android:layout_marginStart="18dp"

            android:layout_toRightOf="@+id/radioButton"
            android:layout_toEndOf="@+id/radioButton" />

        </RadioGroup>
    </RelativeLayout>
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/eventListView"
        android:dividerHeight="20.0sp"
        android:divider="@android:color/transparent"

        android:layout_below="@+id/relativeLayout2"
        android:layout_alignLeft="@+id/relativeLayout2"
        android:layout_alignStart="@+id/relativeLayout2"
        android:layout_marginTop="17dp" />


</RelativeLayout>

ListItem布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="250dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:background="#ffffff"
    android:layout_width="match_parent"

    >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:id="@+id/photoimg"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Medium Text"
        android:id="@+id/datetext"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/titletext"
        android:layout_alignLeft="@+id/titletext"
        android:layout_alignStart="@+id/titletext" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Large Text"
        android:id="@+id/titletext"
        android:layout_below="@+id/photoimg"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="10dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="Medium Text"
        android:id="@+id/locationtext"
        android:layout_below="@+id/datetext"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        />

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/favbtn"
        android:src="@mipmap/star"
        android:scaleType="centerCrop"
        android:background="#00ffffff"
        android:layout_alignBottom="@+id/locationtext"
        android:layout_toLeftOf="@+id/likebtn"
        android:layout_toStartOf="@+id/likebtn"
        android:layout_marginRight="21dp"
        android:layout_marginEnd="21dp" />

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/likebtn"
        android:background="#00ffffff"
        android:src="@mipmap/like"
        android:scaleType="centerCrop"
        android:layout_marginRight="28dp"
        android:layout_alignTop="@+id/favbtn"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="28dp" />
</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

android:focusableInTouchMode="true"

删除它。

Romain Guy写了a post in 2008来解释触摸模式是什么。

聚焦视图将从系统接收关键(如在键盘中)事件。一种观点可以一次集中。

使您的视图在触摸模式下可以集中注意力通常没有意义。还有像EditText这样的例外,您可以在屏幕上考虑多个EditTexts的情况,并希望指定应该键入哪个。

答案 1 :(得分:0)

删除

android:descendantFocusability="beforeDescendants"

android:focusableInTouchMode="true"

来自父布局的

了解android:descendantFocusability

  

beforeDescendants:ViewGroup将在其任何一个之前获得焦点   后代。