【问题标题】:How to scroll table layout in horizontal and vertical in android如何在android中水平和垂直滚动表格布局
【发布时间】:2013-05-13 11:10:27
【问题描述】:

我对表格布局滚动完全感到困惑。我必须实现具有水平和垂直滚动的表格。我还看到了表格修复标题示例,但 tablefixheader 示例使用了适配器来设置数据,但我需要在表格布局中使用 add-view 方法。 我使用了下面的代码,但它不支持双向滚动

      <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="vertical" >

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="fill_parent" 
            android:fadeScrollbars="false">

            <TableLayout
                android:id="@+id/tableLayoutId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </HorizontalScrollView>
    </ScrollView>

【问题讨论】:

    标签: android android-layout android-intent


    【解决方案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>
    

    看看这段代码,看看是否有帮助。

    【讨论】:

    • 很棒的 +1。您应该添加一点解释为什么它有效 =)
    • 我的猜测是它可以工作,因为 android:scrollbars="horizo​​ntal|vertical" 在 OP 错过的两个滚动视图中。
    • 您应该将outsideInset 值更改为outsideOverlay,否则TableLayout 的宽度将与您父母的宽度不匹配。它不会填满屏幕。
    • 我在 ScrollView 中遇到了一些问题,请帮助我,我尝试了您的解决方案但没有成功 @EmilAdz stackoverflow.com/questions/38588702/…
    • @KarthiVenture,您提出的问题与此代码无关。此代码设计用于启用水平和垂直滚动,您只想在您的情况下应用垂直滚动。
    【解决方案2】:

    像这样添加

    <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbars="vertical">
    
            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rv_pins"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbarStyle="outsideOverlay"
                    android:scrollbars="horizontal" />
            </HorizontalScrollView>
    
        </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 2019-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      相关资源
      最近更新 更多