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

mud*_*dit 61 android android-widget android-scrollview

我正在使用TableLayout.我需要为此布局同时进行水平和垂直滚动.默认情况下,我可以在视图中进行垂直滚动,但水平滚动不起作用.

我使用的是Android SDK 1.5 r3.我已经尝试过了android:scrollbars="horizontal".

我在一些论坛上看到,在杯形蛋糕更新中,水平滚动是可能的.

如何让我的布局在两个方向上滚动?

mud*_*dit 134

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

这是它的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>
Run Code Online (Sandbox Code Playgroud)

  • @PedroLoureiro实际上,你发布的链接中的问题是指将`ScrollView`与`ListView`结合起来.这是因为`ListView`在其中有大量优化,不能与周围的`ScorollView`很好地配合.这里发布的答案不是使用`ListView`,因此链接的参数无关紧要. (6认同)
  • 警告:这可能是一种不好的做法.看到这个问题/答案:http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview#4492050 (4认同)
  • 我认为这是一个好主意,但它实际上不允许对角滚动 - 你一次只能滚动一个轴..这有点糟糕 (2认同)

Ash*_*rye 6

它为时已晚,但我希望您的问题能够通过此代码快速解决.没有什么可以做的只是把你的代码放在scrollview下面.

<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>
Run Code Online (Sandbox Code Playgroud)