滚动型/ ListView控件无法在我的手指手势作出回应 [英] ScrollView/ListView does not respond to my finger gesture

查看:151
本文介绍了滚动型/ ListView控件无法在我的手指手势作出回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够用我的手指在屏幕上通过一个列表中滚动,但现在我需要使用轨迹球在手机的底部。是否有我需要实现什么,我做错了什么吗?下面是我的XML与滚动型:

 <滚动型机器人:layout_height =250dip
    机器人:layout_width =FILL_PARENT>
    <的LinearLayout机器人:layout_height =FILL_PARENT
        机器人:layout_width =FILL_PARENT机器人:方向=垂直
        机器人:ID =@ + ID / linearLayout1>
        < ListView控件的android:layout_width =FILL_PARENT机器人:ID =@ + ID /安卓名单
            机器人:layout_height =250dip>< /&的ListView GT;
            < TextView的机器人:ID =@ + ID /安卓空
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=@字符串/ no_user_names/>
    < / LinearLayout中>
< /滚动型>

和下面是从我的类:

该列表使用此方法填充:

 私人无效populateList(){
的String [] =投影新的String [] {NameProviderMetaData.NameTableMetaData._ID,NameProviderMetaData.NameTableMetaData.NAME};
光标C = managedQuery(NAMES_URI,投影,NULL,NULL,NameProviderMetaData.NameTableMetaData.NAME);
的String [] COLS =新的String [] {} NameProviderMetaData.NameTableMetaData.NAME;
INT [] =意见INT新[] {} android.R.id.text1;
适配器=新SimpleCursorAdapter(这一点,android.R.layout.simple_list_item_1,C,COLS,意见);
setListAdapter(适配器);
}

我在别处类的onTouchEvent方法:

  @覆盖
公共布尔onTouchEvent(MotionEvent事件){
    如果(mGestureDetector.onTouchEvent(事件))
    返回true;
    其他
返回false;
}


解决方案

您不能使用一个ListView滚动型(具有相同的方向滚动任意两个视图)内。你应该重新考虑你的布局!

您可以这样做,例如:

 <的LinearLayout机器人:方向=垂直机器人:layout_height =FILL_PARENT
    机器人:layout_width =FILL_PARENT>
        < ListView控件的android:layout_width =FILL_PARENT机器人:ID =@ + ID /安卓名单
            机器人:layout_height =250dip机器人:背景=@空
        机器人:cacheColorHint =@机器人:彩色/透明>< /&的ListView GT;
        < TextView的机器人:ID =@ + ID /安卓空
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=@字符串/ no_user_names/>
< / LinearLayout中>

I want to be able to scroll through a list using my finger on the screen, but right now I need to use the track ball at the bottom of the phone. Is there something that I need to implement or something that I am doing wrong? Here is my XML with the ScrollView:

<ScrollView android:layout_height="250dip"
    android:layout_width="fill_parent">
    <LinearLayout android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:orientation="vertical"
        android:id="@+id/linearLayout1">
        <ListView android:layout_width="fill_parent" android:id="@+id/android:list"
            android:layout_height="250dip"></ListView>
            <TextView android:id="@+id/android:empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no_user_names" />
    </LinearLayout>
</ScrollView>

And below is from my class:

The list is populated using this method:

private void populateList(){
String[] projection = new String[]{NameProviderMetaData.NameTableMetaData._ID,      NameProviderMetaData.NameTableMetaData.NAME};
Cursor c = managedQuery(NAMES_URI,projection,null,null,NameProviderMetaData.NameTableMetaData.NAME);
String[] cols = new String[] {NameProviderMetaData.NameTableMetaData.NAME};
int[] views = new int[] {android.R.id.text1};
adapter = new     SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,c,cols,views);
setListAdapter(adapter);
}

I have an onTouchEvent method elsewhere in the class:

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mGestureDetector.onTouchEvent(event))
    return true;
    else
return false;
}

解决方案

You cannot use a ListView inside a ScrollView (any two views that have same orientation scrolling). You should reconsider your layout!

You could do this for example:

<LinearLayout android:orientation="vertical" android:layout_height="fill_parent"
    android:layout_width="fill_parent">
        <ListView android:layout_width="fill_parent" android:id="@+id/android:list"
            android:layout_height="250dip" android:background="@null"
        android:cacheColorHint="@android:color/transparent"></ListView>
        <TextView android:id="@+id/android:empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no_user_names" />
</LinearLayout>

这篇关于滚动型/ ListView控件无法在我的手指手势作出回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆