Android, How To Add ScrollView Into Screen Which Has Some List Items?
Solution 1:
Try this way
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/GlobalLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="@+id/ListView1"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="@+id/ListView2"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="@+id/ListView3"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
</LinearLayout>
</ScrollView>
Solution 2:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</ScrollView>
Scrollview supports one child layout so make the listview inside the scroll so you will get what you want.
Solution 3:
It doesn't work because android don't know with which view he should scroll, so putting a listview
in a scrollview
its not a bright idea.
try to use visibilty
attribute, use to HIDE
the view that you finich to work with and set VISIBLE
the new.
or use one ListView
and try to populate and remove items after finishing and starting an instruction.
hope that help you
Solution 4:
What you can do is that you can add header and footer into your list view by inflating them. Create three xml layououts and add them in listview using header and footer.
View headerView = View.inflate(this, R.layout.layout_name, null);
lv.addHeaderView(headerView);
use it before setting adapter. lv is listview.
Solution 5:
Use this method and your listview become scrollable inside scrollview:-
ListView lstNewsOffer.setAdapter(new ViewOfferAdapter(
ViewNewsDetail.this, viewOfferList));
getListViewSize(lstNewsOffer);
void getListViewSize(ListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
// do nothing return null
return;
}
// set listAdapter in loop for getting final size
int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
// setting listview item in adapter
ViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight
+ (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight));
}
Post a Comment for "Android, How To Add ScrollView Into Screen Which Has Some List Items?"