Reputation: 771
I am using two listview. It is showing properly but the second listview is not visible in landscape mode. I can't use scrollview in listview.
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E9E0DB"
android:orientation="horizontal"
android:padding="5dp" >
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:orientation="vertical"
android:padding="3dp" >
<ImageView
android:id="@+id/list_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/member_80" />
</LinearLayout>
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Hermoine"
android:textColor="#040404"
android:textSize="16dp"
android:textStyle="normal"
android:typeface="sans" />
<TextView
android:id="@+id/usertype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Basic"
android:textColor="#343434"
android:textSize="12dp" />
<TextView
android:id="@+id/joined_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/usertype"
android:layout_toRightOf="@+id/thumbnail"
android:text="Joined on Sep,21 2013"
android:textColor="#343434"
android:textSize="12dp" />
<TextView
android:id="@+id/total_posts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/usertype"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:scaleType="fitEnd"
android:text="899 Posts"
android:textSize="12dp" />
<TextView
android:id="@+id/membervotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="@drawable/votes_bg"
android:text="388"
android:textColor="#343434"
android:textSize="10dp" />
<View
android:id="@+id/topformline"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="@+id/thumbnail"
android:layout_marginBottom="5dp"
android:layout_marginTop="6dp"
android:background="@android:color/darker_gray"
android:gravity="center" />
<LinearLayout
android:id="@+id/btnsettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/topformline"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="@+id/btnNotification"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/notification_icon" />
<View
android:layout_width="0.8dp"
android:layout_height="25dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray" />
<Button
android:id="@+id/btnMsg"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/messages_icon" />
<View
android:layout_width="0.8dp"
android:layout_height="25dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray" />
<Button
android:id="@+id/btnprofile_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/setting_icon" />
</LinearLayout>
<View
android:id="@+id/bottomformline"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="@+id/btnsettings"
android:layout_marginTop="-15dp"
android:background="@android:color/darker_gray"
android:gravity="center" />
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bottomformline"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#FFFFFF" />
<ListView
android:id="@+id/follow_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/list_view"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#FFFFFF" />
</RelativeLayout>
I want to take the two listview in a single scroll. How to do that? Any suggestions please?
Thanks,
Upvotes: 0
Views: 323
Reputation: 21097
You can put these two listview in scroll view, and disable the scrolling of listviews, Now you will have single scrollview for two listviews.
<ScrollView
android:id="@+id/bottomformline"
android:layout_width="fill_parent" >
<your.package.name.NestedListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" />
<your.package.name.NestedListView
android:id="@+id/follow_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" />
</ScrollView>
public class NestedListView extends ListView implements OnTouchListener, OnScrollListener {
private int listViewTouchAction;
private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99;
public NestedListView(Context context, AttributeSet attrs) {
super(context, attrs);
listViewTouchAction = -1;
setOnScrollListener(this);
setOnTouchListener(this);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
scrollBy(0, -1);
}
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int newHeight = 0;
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (heightMode != MeasureSpec.EXACTLY) {
ListAdapter listAdapter = getAdapter();
if (listAdapter != null && !listAdapter.isEmpty()) {
int listPosition = 0;
for (listPosition = 0; listPosition < listAdapter.getCount()
&& listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
View listItem = listAdapter.getView(listPosition, null, this);
//now it will not throw a NPE if listItem is a ViewGroup instance
if (listItem instanceof ViewGroup){
listItem.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
listItem.measure(widthMeasureSpec, heightMeasureSpec);
newHeight += listItem.getMeasuredHeight();
}
newHeight += getDividerHeight() * listPosition;
}
if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) {
if (newHeight > heightSize) {
newHeight = heightSize;
}
}
} else {
newHeight = getMeasuredHeight();
}
setMeasuredDimension(getMeasuredWidth(), newHeight);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
scrollBy(0, 1);
}
}
return false;
}
}
Upvotes: 1