TableView 行中可滚动的 Android ListView
我的对话框有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/categorylist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0">
<TableRow>
<ListView
android:id="@+id/categorylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
/>
</TableRow>
<TableRow>
<TextView
android:text="New Category"
...
</TextView>
</TableRow>
<TableRow>
<EditText
android:id="@+id/NewCategoryEditText"
...
</EditText>
</TableRow>
<TableRow>
<Button
android:id="@+id/newcategorybutton"
...
/>
</TableRow>
</TableLayout>
我希望列表视图不断增长,直到使用可用空间,然后随着它继续增长而滚动。当带有 Listview 的表格行是 TableLayout 中的最后一行时,此方法效果很好:
(来源:heeroz.com)
但是,在列表顶部不是很直观。当我将“固定”表格行移动到底部时,一旦列表视图增长到应该滚动的位置,ListView 就会将它们推离屏幕。仅当没有其他内容可以从屏幕上推出时,ListView 才会开始滚动:
(来源:heeroz.com)
我怎样才能改变我的布局,以便带有按钮和 EditText 视图的表行仍然可见?
I have the following layout for a dialog:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/categorylist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0">
<TableRow>
<ListView
android:id="@+id/categorylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
/>
</TableRow>
<TableRow>
<TextView
android:text="New Category"
...
</TextView>
</TableRow>
<TableRow>
<EditText
android:id="@+id/NewCategoryEditText"
...
</EditText>
</TableRow>
<TableRow>
<Button
android:id="@+id/newcategorybutton"
...
/>
</TableRow>
</TableLayout>
I would like the Listview to grow until the available space is used, then scroll as it coninues to grow. This works fine when the table row with the Listview is the last one in the TableLayout:
(source: heeroz.com)
However, having the Add button at the top of the list is not very intuitive. When I move the "fixed" table rows to the bottom, the ListView will push them off the screen once it grows to a point where it should scroll. The ListView will only then begin to scroll when there is nothing else left that can be pushed off the screen:
(source: heeroz.com)
How can I change my layout so that the table rows with the button and the EditText view remain visible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用
TableLayout
而不是LinearLayout
和android:orientation="vertical"
是否有特殊原因?如果您使用LinearLayout
,您可以在ListView
上指定android:layout_weight="1"
,您应该会得到您想要的结果。Is there a particular reason you're using a
TableLayout
instead of aLinearLayout
withandroid:orientation="vertical"
? If you use theLinearLayout
you can specifyandroid:layout_weight="1"
on theListView
and you should get the results you want.