【问题标题】:How to put a very long table layout inside the horizontal Scroll view in the CORRECT way?如何以正确的方式在水平滚动视图中放置一个很长的表格布局?
【发布时间】:2012-12-02 22:11:58
【问题描述】:

我尝试查看大量示例和帖子,但没有一个符合我的问题。

我需要制作一个包含许多列的很长(水平)的表格,因此不可能在单个屏幕上显示。而且我不想把表格弄得乱七八糟,因为以这种方式展示我的表格很重要。

我在下面粘贴了我的 XML 布局(包括主要的重要布局)

问题是如果我删除代码:

android:fillViewport="true"

Horizo​​ntalScrollView 然后我的桌子在里面,被挤在一个地方,特别是在它的左侧。它甚至没有使用太多这个 Horizo​​ntalScrollView 容器区域。

而且, 如果我使用此代码,则此 Horizo​​ntalScrollView 会在其中显示我的整个表格 - 列被挤压以确保它们适合此滚动视图。

我只想让这个滚动视图只显示适合屏幕宽度的表格布局的内容,这样我就可以滚动剩余的列。但是现在,我似乎什么都没有附近。

那么我该如何解决我的问题呢?我是不是做错了什么?

这也是我的 XML 布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal"
    android:fillViewport="true">
    <TableLayout
        android:id="@+id/bot_scoreBoard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/table_shape"
        android:orientation="horizontal"
        android:stretchColumns="*" >

        <TableRow
            android:layout_height="fill_parent"
            android:layout_margin="2dp"
            android:background="#ffffff"
            >
            <TextView
            />
               ....
            more than 16 columns of made using TextView
 ....
        </TableRow>
    </TableLayout>

</HorizontalScrollView>

</LinearLayout>

【问题讨论】:

    标签: android horizontalscrollview android-tablelayout


    【解决方案1】:

    我得到了答案。那是因为我用的是

     android:stretchColumns="*" 
    

    在表格布局中。

    加上我的 TextView 是列,需要一些特定的宽度大小,而不仅仅是

    android:layout_width="fill_parent" or "wrap_content"
    

    这些都是问题。

    【讨论】:

      【解决方案2】:

      你应该用LinearLayout 包裹你的TableLayout

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" >
      
      <HorizontalScrollView
          android:id="@+id/horizontalScrollView"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:fillViewport="true"
          android:scrollbars="horizontal" >
      
          <LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:orientation="horizontal" >
      
              <TableLayout
                  android:id="@+id/bot_scoreBoard"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:background="@drawable/table_shape"
                  android:orientation="horizontal"
                  android:stretchColumns="*" >
      
                  <TableRow
                      android:layout_height="fill_parent"
                      android:layout_margin="2dp"
                      android:background="#ffffff" >
      
                      <TextView />
                 ....
              more than 16 columns of made using TextView
           ....
                  </TableRow>
              </TableLayout>
          </LinearLayout>
      </HorizontalScrollView>
      

      【讨论】:

      • 我不确定这会有什么帮助。我试过了,它仍然没有达到我想要的效果。
      【解决方案3】:

      您正在使用android:stretchColumns="*",您必须对layout_width 使用一些确定的值,而不是match_parentwrap_content

      例如。 layout_width = "250dp"

      【讨论】:

        猜你喜欢
        • 2017-05-19
        • 1970-01-01
        • 2019-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多