【问题标题】:How to scroll a LinearLayout horizontally?如何水平滚动LinearLayout?
【发布时间】:2012-10-04 14:21:26
【问题描述】:

我有一个比屏幕大的 LinearLayout。我想水平滚动它。我有下一个代码,但它不起作用。有人可以帮帮我吗?

<HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/gm_movimientos"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="horizontal" >

    </LinearLayout>
</HorizontalScrollView>

【问题讨论】:

  • 当线性布局大于屏幕时,我尝试水平滚动但没有任何反应。
  • 确保检查布局上的换行符。

标签: android android-linearlayout horizontalscrollview


【解决方案1】:

您的 Horizo​​ntalScrollView 宽度需要设置为 match_parent 或固定大小。现在 ScrollView 正在扩展到与 LinearLayout 相同的尺寸(即它的边界也在屏幕之外)。

【讨论】:

  • 我首先将 Horizo​​ntalScrollView 设置为 match_parent 并在 2000dp 旁边(以确保大于 LinearLayout)但仍然无法正常工作:(
  • Horizo​​ntalScrollView 实际上需要比 LinearLayout 小。您在 ScrollView 的可见大小边界内滚动。
  • 不,它不会工作。您可以定义大于设备宽度或高度的宽度或高度,但它只会占用设备宽度或高度,而不是大于该值的单个 dpi。
  • 现在可以工作了,Horizo​​ntalScrollView 出现了!非常感谢!
  • 但是如果您的视图的内容(其他视图或位图)大于设备宽度,则水平滚动视图将起作用...
猜你喜欢
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 2018-06-21
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 2023-03-24
  • 1970-01-01
相关资源
最近更新 更多