ListView控件没有在Android上滚动 [英] ListView without scroll on Android

查看:122
本文介绍了ListView控件没有在Android上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置列表视图显示不滚动的所有项目。结果
下面是我的布局:

I want to set listview to show all items without scroll.
Below is my layout:

<LinearLayout
          android:id="@+id/layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" >

      <TextView
      android:id="@+id/tv1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Large Text"
      android:textColor="@android:color/black"
      android:textAppearance="?android:attr/textAppearanceLarge" />

      <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <TextView
         android:id="@+id/tv2"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Large Text"
         android:textColor="@android:color/black"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     </LinearLayout>

在LinearLayout中是属于滚动视图。结果
所以,我想设置列表视图由父的滚动的所有项目和滚动。结果
我该怎么办呢?

The linearlayout is belong to a scrollview.
So I want to set the listview all items and scroll by the parent's scroll.
How can I do it?

推荐答案

这是你应该如何设置你的ListView的滚动视图,但就像别人回答,你永远不应该把一个列表视图中滚动视图,特别是如果列表视图将含有大量的项目

This is how you should set your listview in a scrollView, but just like somebody else answered, you should never put a listview in a scrollview, especially if the listview will contain a lot of items

ListView lv = (ListView)findViewById(R.id.list);  // your listview inside scrollview

lv.setOnTouchListener(new ListView.OnTouchListener() 
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        int action = event.getAction();
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
            // Disallow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle ListView touch events.
        v.onTouchEvent(event);
        return true;
    }
});

这篇关于ListView控件没有在Android上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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