Search code examples
androidandroid-linearlayouthorizontalscrollview

How to scroll a LinearLayout horizontally?


I have a LinearLayout that I do larger than the screen. I want to scroll that in horizontal. I have the next code but it doesn't work. Can anybody help me?

<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>

Solution

  • Your HorizontalScrollView width needs to be set to either match_parent or a fixed size. Right now the ScrollView is expanding to the same dimensions of the LinearLayout (i.e. its bounds are also going off of the screen).