【问题标题】:Scrollable Android ListView in TableView RowTableView 行中的可滚动 Android ListView
【发布时间】:2011-03-11 08:37:27
【问题描述】:

我的对话框布局如下:

<?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 增长直到可用空间被使用,然后随着它继续增长而滚动。当具有 Listview 的表格行是 TableLayout 中的最后一个时,这可以正常工作:


(来源:heeroz.com

但是,将“添加”按钮放在列表顶部并不是很直观。当我将“固定”表行移动到底部时,一旦 ListView 增长到应该滚动的点,它就会将它们推离屏幕。只有当没有其他东西可以从屏幕上推出时,ListView 才会开始滚动:


(来源:heeroz.com

如何更改布局以使带有按钮的表格行和 EditText 视图保持可见?

【问题讨论】:

    标签: android listview scroll tablelayout


    【解决方案1】:

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

    【讨论】:

    • 我不记得具体原因,我会尝试您的建议。谢谢。
    • 效果更好,到目前为止我还没有发现任何缺点,.谢谢!
    • 使用 layout_weight 时,记得使用 layout_width="0dp"
    猜你喜欢
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多