TableView 行中可滚动的 Android ListView

发布于 2024-09-08 05:36:51 字数 1876 浏览 2 评论 0原文

我的对话框有以下布局:

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

alt text
(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:

alt text
(source: heeroz.com)

How can I change my layout so that the table rows with the button and the EditText view remain visible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2024-09-15 05:36:51

您使用 TableLayout 而不是 LinearLayoutandroid:orientation="vertical" 是否有特殊原因?如果您使用 LinearLayout,您可以在 ListView 上指定 android:layout_weight="1",您应该会得到您想要的结果。

Is there a particular reason you're using a TableLayout instead of a LinearLayout with android:orientation="vertical"? If you use the LinearLayout you can specify android:layout_weight="1" on the ListView and you should get the results you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文