开发者

list inside scrollview

开发者 https://www.devze.com 2023-01-21 19:01 出处:网络
On my screen I have a list view and a button. my list has like 8 item. I would like my screen to scroll if both these items does not fit in. I don\'t want my list to have scr开发者_如何学编程oll but t

On my screen I have a list view and a button. my list has like 8 item. I would like my screen to scroll if both these items does not fit in. I don't want my list to have scr开发者_如何学编程oll but the complete layout including both list & button. If I use the below layout it only shows on item inside the list and I have to scroll within the list to go to next item.

<?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" >
<LinearLayout
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <ListView android:id="@android:id/list"
            android:layout_height="wrap_content" android:layout_width="fill_parent"
            android:background="@drawable/round_background" />

        <Button android:text="Search" android:id="@+id/carSearchButton"
            android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>


You can't put a ListView inside a ScrollView. Of GridView, or whatever View that handles scrolling on the same axis as the ScrollView does. That way the framework wouldn't know which View should handle the scrolling event. This layout won't produce an error when you compile it, but it won't work properly.

What you should do here: dump the outer ScrollView, you don't need it. Only use a ListView, and add the button to the ListView, using .addFooter(), that's the easiest way. This way your button'll appear as a list element, but you don't have to mess around with a custom adapter.


Scythe kind of answers my question but I wanted more then one one control below the list also on another screen I wanted 2 lists. So in order to have the scroll bar working with list view I had to fix the height of the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消