android:there are a listview in ScrollView so listview Scrolling not happend.

社会主义新天地 提交于 2019-12-13 09:46:02

问题


I have this type of layout

<LinearLayout>
<ScrollView>
<LinearLayout>
    <ImageView/>
    <button>
    <ListView>
</LinearLayout> 
</ScrollView>

So in this Case my List view Scrolling not happens and my View Scrolling is perform i want also perform Listview Scrolling when data is more. and List view is need to put in Scroll view parent layout so how can solve this problem please help me.


回答1:


Never put a ListView inside of a ScrollView. Never. You have two options:

  1. If you don't necessarily want the ImageView and Button to scroll away, just remove the ScrollView:

    <LinearLayout android:orientation="vertical" ...>
        <ImageView .../>
        <Button .../>
        <ListView .../>
    </LinearLayout>
    
  2. This one is slightly more complicated. Implement a custom list adapter (by extending BaseAdapter, for example, or one of its subclasses) and, in your getView method return the ImageView and the Button for positions 0 and 1, respectively. This way, your layout will only contain a ListView, but its first two items will be the ImageView and the Button.

P.S.: Never put a ScrollView in a ListView, either.




回答2:


I don't understand for what you try to use ScrollView with ListView too? If your layout is really big than screen, then will be good to use a ScrollView like described here:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:scrollbars="vertical" 
        android:visibility="visible">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  ..your any xml data
</LinearLayout>
</ScrollView>

ListView has internal scroll tool, so you just need to choose a correct way to use it.



来源:https://stackoverflow.com/questions/7444680/androidthere-are-a-listview-in-scrollview-so-listview-scrolling-not-happend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!