hirra
hirra

Reputation: 977

About listview & scrollview

It's an old and old question.Listview locates inside the scrollview beside a linearlayout. Maybe there are tow solutions: 1.give up using it. 2.confirm the height of listview or make the height dynamic.While,when I code in this way,I find the focus is always on the bottom of the listview.And request.setFocus() donen't work....

How to deal with it??

Upvotes: 0

Views: 122

Answers (2)

jkernacs
jkernacs

Reputation: 21

You should not place the list view inside a ScrollView. If you want to show something above or below the list and want to scroll them together the list, you just need to use header or footer views. An example:

The main screen content:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

The footer view (list_footer.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"><!-- the footer content -->
</LinearLayout>

Adding footer in code: You should do it before setting an adapter for the list

 ListView listView = (ListView) view.findViewById(R.id.main_list);
 View footer = LayoutInflater.from(getActivity()).inflate(R.layout.list_footer, listView, false);
 listView.addFooterView(footer);

        listView.setAdapter(yourAdapter);

Upvotes: 2

chinglun
chinglun

Reputation: 647

A ScrollView can only hold a child. If that Linearout is really necessary(usually it's just a holder), you should do this:

<ScrollView>
    <LinearLayout>
        <ListView>
        <!-- Blahblah -->
        </ListView>
        <LinearLayout>
        <!-- Blahblah -->
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Upvotes: 0

Related Questions