簡體   English   中英

將TableLayout放在ScrollView中?

[英]Putting a TableLayout inside a ScrollView?

因此,我有一個TableLayout想要放入ScrollView中。 但是我有一個問題:

TableLayout最初是空的,我通過點擊按鈕以編程方式向其中添加TableRows 如果我將TableLayout正常放入ScrollView正常工作。

但是我想將TableLayout放在ScrollView的底部。 因此,每次添加TableRow ,最后一個單元格將始終與父級ScrollView的底部對齊。 (有點像聊天應用程序的工作方式-當您按發送時,您的消息將被添加在底部,而所有其他消息將被向上推)。

發生的事情是,如果我使用android:layout_gravity="bottom"嘗試實現此目的,那么我將看不到任何向上推出屏幕視圖的行(我無法向上滾動)。 但是,由於某種原因,我可以向下滾動到空狀態,因為最后一個TableRow應該在底部,所以這不可能。

基本上,問題是我可以在沒有TableRows地方向下滾動,但不能在有TableRows地方向上滾動。

這是相關的XML代碼:

<ScrollView
    android:id="@+id/tableScrollView"
    android:layout_width="match_parent"
    android:layout_weight="0.7"
    android:layout_height="0dip"
    android:scrollbars="none"
    android:orientation="vertical"
    android:background="@drawable/stripes_background" >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="bottom">    

        <TableLayout
            android:id="@+id/outputTable"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:divider="@drawable/table_divider" 
            android:showDividers="middle">    
    </TableLayout>
    </RelativeLayout>

</ScrollView>

看來您應該使用ListView或其某些變體; 它提供了與滾動內容相關的各種優化的支持。 看一下可用於自定義ListView實現的一些教程和開發人員文檔。

編輯檢查問題Listview更新列表后滾動到列表的末尾,以獲取有關使用ListView執行滾動操作所需的詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM