在我的代码中有四个listview我如何使屏幕可滚动显示所有listview的所有数据?不是这个代码使listview可滚动我不希望listview滚动想要ScreenScrollable像这样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>
答案 0 :(得分:43)
在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;
}
}
如何使用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>
并设置
yourListView.setExpanded(true);
通过使用此自定义组件,您可以在scrollview中设置多个listview。我正在使用这个自定义组件。
享受:)
答案 1 :(得分:3)
永远不要在listview
Scrollview
如果您拥有固定数量的观看次数,请不要尝试使用listview
,而是使用LinearLayout
。由于listview将有自己的滚动,这也不是一个好的用户体验。
答案 2 :(得分:0)
你可以尝试针对这个问题展开listview, 尝试以下链接 http://www.javacodegeeks.com/2013/06/android-expandablelistview-with-custom-adapter-baseexpandablelistadapter.html