【问题标题】:TableLayout within HorizontalScrollViewHorizo​​ntalScrollView 中的 TableLayout
【发布时间】:2011-11-11 17:31:10
【问题描述】:

我正在使用以下代码创建一个可水平滚动的TableLayout

      <?xml version="1.0" encoding="utf-8"?>
      <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:minWidth="200dp"
           android:scrollbars="none">

       <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"            android:id="@+id/maintable2"
                android:layout_width="fill_parent"                  
                android:layout_height="fill_parent"                     
                android:stretchColumns="*"                      
                android:background ="#dddddd"           
                android:scrollbars="none"   >       
       </TableLayout>               
   </HorizontalScrollView>

我需要TableLayout 中的列至少填满屏幕(即,如果只有一列,则该列的边框应延伸到整个屏幕,如果有两列,则两列的边框应该填满屏幕等)。

我该怎么做?

【问题讨论】:

  • 好吧android:stretchColumns="*" 应该这样做。有什么问题?

标签: android view tablelayout


【解决方案1】:

我遇到了同样的问题。我通过将android:fillViewport="true" 添加到HorizontalScrollView 来解决它。

【讨论】:

    【解决方案2】:

    显示三个大小相等的列并排

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"                  
        android:layout_height="fill_parent"
        android:background ="#dddddd"
        />
    <TableLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"                  
        android:layout_height="fill_parent"
        android:background="#ffffff"
        />
    <TableLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"                  
        android:layout_height="fill_parent"
        android:background ="#dddddd"
        />
    

    【讨论】:

    • Benjamin,您的回答存在严重缺陷。它不仅不使用 Horizo​​ntalScrollView,而且还使用了三个单独的 TableLayout,每个 TableLayout 都用作列。那没有意义。应该有一个带有 TableRow(s) 的 TableLayout,其中包含视图作为列的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多