为什么ListView控件不能在滚动型中使用? [英] Why ListView cannot be used in a ScrollView?

查看:232
本文介绍了为什么ListView控件不能在滚动型中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很多教程和示例但为何ListView控件不能在滚动型中使用?

只有答案是
是一个ListView,使其不滚动是非常昂贵,违背的ListView的整个目的。 resources.

我有下面的XML文件。

  .........
<滚动型
   机器人:ID =@ + ID / SV
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =WRAP_CONTENT
   机器人:layout_below =@ + ID / textView2>
      < ListView控件
         机器人:ID =@ + ID /列表
         机器人:layout_width =275dp
         机器人:layout_height =200dp>
     < /&的ListView GT;
< /滚动型>
.........

在这个XML文件,我已经使用


  

的WRAP_CONTENT代替200dp高度的ListView


 的ListView LV =(ListView控件)findViewById(R.id.list);
   lv.setAdapter(新EfficientAdapter(本));

但亘古不变的工作。

什么是具体的身高和体重的替代滚动列表项。

但是我试试这个:

 < ListView控件
         机器人:ID =@ + ID /列表
         机器人:layout_width =275dp
         机器人:layout_height =200dp>
     < /&的ListView GT;

 <滚动型机器人:layout_width =FILL_PARENT机器人:ID =@ + ID / SV
        机器人:layout_height =WRAP_CONTENT机器人:layout_below =@ + ID / textView2>
    <的LinearLayout的android:layout_width =FILL_PARENT
        机器人:方向=垂直
        机器人:layout_height =WRAP_CONTENT>
        < ListView的机器人:ID =@ + ID /列表的android:layout_width =275dp
            机器人:layout_height =240dp>< /&的ListView GT;
    < / LinearLayout中>
    < /滚动型>

如果没有scollview但滚动列表项是确定的,但相当不smothly。
我有尝试但不能得到更多的想法背后。

编辑:

是不是列表视图已经inbuild滚动功能即可。所以,没有必要定义滚动视图列表视图里面。这意味着在滚动视图没有必要?


解决方案

问题是不是在ListView但滚动型

这两个观点需要采取垂直滚动的控制研究,如果你有一个滚动视图,并在同一布局ListView和用户向下滚动,其中一个必须考虑的重点,因此滚动?

这是一个具有普遍和简单的解决方案的共同问题(此解决方案来自罗曼盖伊从谷歌Android团队!)!在滚动视图不使用一个ListView

如果你想一个有趣的视频/谈​​论你可以从谷歌I / O会谈看着它:的 ListView控件的世界我真的建议你去看看:)

I found many tutorials and examples butWhy ListView cannot be used in a ScrollView?

Only answers is Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. resources.

I have following xml file.

.........
<ScrollView 
   android:id="@+id/sv" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_below="@+id/textView2">
      <ListView 
         android:id="@+id/list"
         android:layout_width="275dp"
         android:layout_height="200dp">
     </ListView>
</ScrollView>
.........

In this xml file, i have already use

wrap_content instead of 200dp height of listview

   ListView lv = (ListView) findViewById(R.id.list);
   lv.setAdapter(new EfficientAdapter(this));

but doesnot work.

What is the alternative scrolling list item for specific height and weight.

But I have try this:

<ListView 
         android:id="@+id/list"
         android:layout_width="275dp"
         android:layout_height="200dp">
     </ListView>

or

<ScrollView android:layout_width="fill_parent" android:id="@+id/sv" 
        android:layout_height="wrap_content"   android:layout_below="@+id/textView2">   
    <LinearLayout android:layout_width="fill_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content">
        <ListView android:id="@+id/list" android:layout_width="275dp"
            android:layout_height="240dp"></ListView>
    </LinearLayout>
    </ScrollView>

Without scollview but scrolling the listitem is ok but quite not smothly. I have try this but could not get more idea behind this.

Edited:

Is it right Listview have inbuild scrolling capabilities. So not necessary to define listview inside the scrollview. It means scrollview in not necessary?

解决方案

The problem is not the ListView but the ScrollView

Those two views need to takes controll of vertical scrolling, if you have a scrollview and a listview in the same layout and the user scroll down, which one have to take the focus and so the scroll?

This is a common problem that has a common and easy solution (this solution comes from Romain Guy from Google Android team!): don't use a listview in a scrollview!

If you want an interesting video/talk you can watch it from Google I/O talks: The world of ListView I really suggest you to take a look :)

这篇关于为什么ListView控件不能在滚动型中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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