我正在开发一个应用程序,在其中一项活动中我有一个列表视图。它是一个动态列表视图,填充了它自己的 arrayadapter,所以它的扩展是未知的。我希望当它超过屏幕大小时,它会到达底部并向下滚动。
为了实现这一点,我必须给列表一个固定的大小,特别是 471,这样它就占据了屏幕的很大一部分,我可以上下滚动。如果我给它 match_parent 属性,它会保留在一行中,并且单个元素保留在顶部,我可以滚动但所有元素都保留在那里,无论大小。
有没有办法调整所有屏幕的列表并使其在屏幕上完整?
我把布局留给你:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.oftecnica2.agendajose.MainActivity"
android:orientation="vertical"
android:gravity="center"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:id="@+id/lista"
android:divider="@drawable/separador"
android:layout_height="475dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
这是我用来填充列表视图的自己的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="53dp"
android:layout_height="75dp"
android:id="@+id/imageView"
android:src="@drawable/iconoreunion" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nº"
android:id="@+id/textView"
android:paddingRight="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtnumero"
android:paddingRight="30dp"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Act1Fecha"
android:id="@+id/textView3"
android:paddingRight="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtfecha"
android:paddingRight="10dp"
android:layout_weight="0.25"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Act1Nombre"
android:id="@+id/textView5"
android:paddingRight="10dp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtnombre"
android:paddingRight="30dp"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
第一件事是,拥有一个
listview
内部 ascrollview
是一个非常糟糕的主意,如果您需要一个带有顶部或底部视图的列表视图,您必须使用addHeaderView()
and方法在其上方或下方添加视图addFooterView()
。你肯定会发生的是,滚动视图正在占用列表视图的大小,以便滚动视图具有整个屏幕的大小添加:
一切顺利
你可以这样做..
这样您就不会变得复杂......以这种简单的方式,您的屏幕只会显示 ListView,如果需要的话。
您是否尝试过删除操作栏?
首先在你的主容器中
LinearLayout
,你定义了:这是正确的,但是您定义了填充将产生空间:
移除填充物。
另一个重要的一点是,您不需要 a
Scrollview
来包含 ListView,因为它有自己的 Scroll,删除ScrollView
和它的LinearLayout
.这是一个例子: