【问题标题】:How to make a horizontally scrollable TableLayout?如何制作水平可滚动的 TableLayout?
【发布时间】:2020-06-23 05:29:08
【问题描述】:

我有一个带有约束布局的可滚动视图/布局。

在这个布局里面我有很多其他的东西。在布局的底部,我需要一个以编程方式创建的表格布局。

如何使这个 TableLayout 可以水平滚动?

<ScrollView
            android:id="@+id/testlay"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:layout_marginTop="5dip"
            android:layout_marginStart="60dp"
            android:fillViewport="false"
            android:scrollbarStyle="outsideInset"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayoutProductTableHeader">

            <TableLayout
                android:id="@+id/linearLayoutProductTable"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:focusable="true"
                android:gravity="center"
                android:isScrollContainer="true"
                android:stretchColumns="*"
                tools:ignore="MissingConstraints">

            </TableLayout>
        </ScrollView>

我也尝试在 ScrollView 中使用 Horizo​​ntalLayout,但它不起作用。

【问题讨论】:

    标签: android kotlin scroll scrollview tablelayout


    【解决方案1】:

    这就是我实现它并为我工作的方式:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <ScrollView 
            android:id="@+id/layout" 
            android:layout_height="match_parent"         
            android:scrollbars="horizontal|vertical" 
            android:layout_width="match_parent"     
            android:layout_marginTop="5dip"     
            android:scrollbarStyle="outsideInset"
            android:fillViewport="true"> 
      <HorizontalScrollView 
        android:id="@+id/horizontalView" 
        android:layout_height="wrap_content"     
        android:scrollbars="horizontal|vertical" 
        android:layout_width="wrap_content"     
        android:layout_marginTop="5dip">
               <TableLayout
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                    android:id="@+id/tlGridTable" >   
               </TableLayout>
    </HorizontalScrollView>
    </ScrollView>
    
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      好的,我认为问题在于我以编程方式添加了表格行和列。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-21
        • 1970-01-01
        • 2020-06-17
        • 2021-09-02
        相关资源
        最近更新 更多