我有一个带有更多控件的活动:一个 Spinner、2 个编辑框、一个按钮一些文本视图和一个列表视图,然后是另一个按钮。全部采用垂直布局。
OnClick 第一个按钮,我将一个新项目添加到列表视图(基于其他编辑框值和微调器值)。这样,列表视图不断增长。我想知道是否有任何方法可以使列表视图的高度在每次添加后自动扩展。扩展后底部按钮也应保留在底部。
我想要这个,因为我的列表视图非常小,因为布局上有很多控件。它几乎不会同时显示 2 个项目。所以用户不能一次看到所有添加的项目,他必须在这个2 项目列表视图中滚动才能看到所有项目。这看起来既糟糕又愚蠢。而且用户还必须知道列表中有超过 2 个项目,因为没有直接看到它们,他可以假设只有 2 个项目并且应用程序无法运行,因为没有新项目出现。我希望我说清楚了。
请告诉我是否有可能或在这种情况下最好的方法是什么?
我的布局如下:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".NewStuff" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Back" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Page title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Choose item" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner1"
android:layout_below="@+id/spinner1"
android:text="Property 1" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_alignRight="@+id/spinner1"
android:layout_below="@+id/textView3"
android:ems="10"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:text="Property 2" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/textView4"
android:ems="10"
android:inputType="numberDecimal" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:layout_below="@+id/editText2"
android:text="Add to listview" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_toLeftOf="@+id/button1"
android:text="Save listview contents" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2" >
</ListView>
</RelativeLayout>