代码之家  ›  专栏  ›  技术社区  ›  mudit

如何使我的布局水平和垂直滚动?

  •  55
  • mudit  · 技术社区  · 17 年前

    我用的是表格布局。对于这个布局,我需要水平和垂直滚动。默认情况下,我可以在视图中进行垂直滚动,但水平滚动不起作用。

    我正在使用android sdk 1.5r3。我已经试过了 android:scrollbars="horizontal" .

    我在一些论坛上读到,在纸杯蛋糕更新,水平滚动是可能的。

    我怎样才能让我的布局在两个方向上滚动?

    4 回复  |  直到 9 年前
        1
  •  129
  •   hareesh J    9 年前

    我能够找到一种简单的方法来实现滚动行为。

    这是它的XML:

    <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="320px" android:layout_height="fill_parent">
    
            <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/linlay" android:layout_width="320px"
                android:layout_height="fill_parent" android:stretchColumns="1"
                android:background="#000000"/>
    
        </HorizontalScrollView>
    
    </ScrollView>
    
        2
  •  5
  •   Ashish Tikarye    9 年前

    太晚了,但我希望您的问题能用这段代码很快解决。 没什么可以做的,只要把你的代码放在下面的滚动视图。

     <HorizontalScrollView
                android:id="@+id/scrollView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent">
    
              <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    //xml code
              </ScrollView>
      </HorizontalScrollView>
    
        3
  •  1
  •   Community Mohan Dere    9 年前

    在这篇文章中 Scrollview vertical and horizontal in android 他们谈论一个可能的解决方案,引用:

    matt clark基于android源代码构建了一个自定义视图,它似乎工作得很好: http://blog.gorges.us/2010/06/android-two-dimensional-scrollview

    请注意,该页中的类在计算视图的水平宽度时有一个错误。曼纽尔·希尔蒂的一个修正是在评论中:

    解决方案:将第808行的语句替换为以下内容:

    final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED);
    
        4
  •  0
  •   Michael Celey Luís Ledebour    13 年前

    使用此:

    android:scrollbarAlwaysDrawHorizontalTrack="true"
    

    例子:

    <Gallery android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarAlwaysDrawHorizontalTrack="true" />