Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make multiplelistview in Scrollview?

Tags:

android

in my code there is four listview how do i make screen scrollable to show all data of all listview? not this code make listview scrollable i dont want listview scrolling want ScreenScrollable like this image

   <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffff"
   android:orientation="vertical" >

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/imagelogo2"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/test_button_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:paddingTop="20dp"
        android:src="@drawable/back" >
     </ImageView>

     <ImageView
        android:id="@+id/test_button_image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingLeft="5dp"
        android:paddingRight="15dp"
        android:paddingTop="15dp"
        android:src="@drawable/options1" />
     </RelativeLayout>

  <TextView
    android:id="@+id/ElemenrySchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="elementry"
    android:textSize="17dp" >
     </TextView>

  <LinearLayout
    android:id="@+id/lytContent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
       </LinearLayout>

    <TextView
    android:id="@+id/MiddleSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="Middle"
    android:textSize="17dp" >
   </TextView>

   <LinearLayout
    android:id="@+id/lytContent2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu22"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

   <TextView
    android:id="@+id/HighSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="HighSchool"
    android:textSize="17dp" >
   </TextView>

    <LinearLayout
    android:id="@+id/lytContent3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

      <ListView
        android:id="@+id/listMainMenu33"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

   <TextView
    android:id="@+id/AtipicalSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="Atipical"
    android:textSize="17dp" >
   </TextView>

   <LinearLayout
    android:id="@+id/lytContent4"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu44"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

  </LinearLayout>
like image 422
user2699824 Avatar asked Aug 21 '13 09:08

user2699824


2 Answers

use this custom listview component inside scrollview.

package com.app.Settings;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableHeightListView extends ListView
{

boolean expanded = false;

public ExpandableHeightListView(Context context)
{
    super(context);
}

public ExpandableHeightListView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public ExpandableHeightListView(Context context, AttributeSet attrs,int defStyle)
{
    super(context, attrs, defStyle);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // But do not use the highest 2 bits of this integer; those are
        // reserved for the MeasureSpec mode.
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
}
} 

HOW TO USE IN XML?

 <yourPackageName.ExpandableHeightListView
        android:id="@+id/expandableHeightlist1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   
        android:cacheColorHint="#00000000"
        android:fadingEdge="none"
        android:focusable="false"
        android:scrollbars="none"
        >
    </yourPackageName.ExpandableHeightGridView>

and set

yourListView.setExpanded(true);

By using this custom component you can set multiple listview inside scrollview. i am using this custom component.

Enjoy :)

like image 51
Sanket Kachhela Avatar answered Oct 21 '22 06:10

Sanket Kachhela


Never use two listview inside Scrollview

Don't try to use listview , use a LinearLayout instead , if you have got a fixed number of views. As listview will have its own scroll and this won't be a good user experience too.

like image 43
Prateek Avatar answered Oct 21 '22 05:10

Prateek