Reputation: 31
I have two listview. i need to scroll one listview as the continuation of another list view. In between the list there should be a text view. if i use the two listview and textview inside a scrollview icould not able to scroll both the list. if i use the listview without scrollview i can see the two listview but scrolling is not continues.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FAF0BE" >
<Button
android:id="@+id/btnheader"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#A1CAF1"
android:text="DisoderDetail" />
<TextView
android:id="@+id/txtTmtDnam"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnheader"
android:layout_marginLeft="@dimen/marginLLeft"
android:layout_marginTop="@dimen/marginTopp"
android:text="jgjggjh"
android:textColor="#000000" />
<TextView
android:id="@+id/txtdisDdtail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtTmtDnam"
android:layout_marginLeft="@dimen/marginLLeft"
android:layout_marginTop="@dimen/marginTopp"
android:text="jgjggjh hjhhhjh jhjhh"
android:textColor="#000000" />
<RelativeLayout
android:id="@+id/Rvlytt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/lyt2"
android:layout_below="@id/txtdisDdtail"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/marginBottomm"
android:layout_marginTop="@dimen/marginTop"
android:orientation="horizontal" >
<ImageView
android:id="@+id/starimg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:onClick="star1Clicked"
android:src="@drawable/starunselected"
android:tag="1" />
<ImageView
android:id="@+id/starimg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/starimg1"
android:onClick="star2Clicked"
android:src="@drawable/starunselected"
android:tag="2" />
<ImageView
android:id="@+id/starimg3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/starimg2"
android:onClick="star3Clicked"
android:src="@drawable/starunselected"
android:tag="3" />
<ImageView
android:id="@+id/starimg4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/starimg3"
android:onClick="star4Clicked"
android:src="@drawable/starunselected"
android:tag="4" />
</RelativeLayout>
<ScrollView
android:id="@+id/Scrlvw"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/Rvlytt2" >
<RelativeLayout
android:id="@+id/rvl1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtDcmt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="@dimen/marginTop"
android:text="comment"
android:textColor="#000000" />
<ListView
android:id="@+id/lstvwDis11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtDcmt" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rvl2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/rvl1"
>
<TextView
android:id="@+id/txtDrate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lstvwDis11"
android:layout_marginTop="@dimen/marginTop"
android:text="Rate"
android:textColor="#000000" />
<ListView
android:id="@+id/lstvwDis12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtDrate" >
</ListView>
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/Rvlt22"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<EditText
android:id="@+id/Edtcmmt"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:background="#ffffff"
android:hint="Add a comment"
android:textColor="#000000" />
<Button
android:id="@+id/btnpost"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/Edtcmmt"
android:onClick="OnPostbtnclick"
android:text="Post" />
</RelativeLayout>
</RelativeLayout>
Upvotes: 0
Views: 1407
Reputation: 1073
This is not correct design for starters but if you want to stick with the design one quick fix that will make your code work is to put both of your listViews inside one more list view and put that under scroll view. that should solve your problem of scrolling.
Upvotes: 2
Reputation: 8023
When placing ListView
inside ScrollView
I use the following method to set listView height and the scrolling works properly. Use this after you've added all views to your listview.
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
if (listItem instanceof ViewGroup) {
listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
}
Upvotes: 0