Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

android - how to make multiplelistview in Scrollview?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...