How can I make a Linear layout horizontally scrollable? I just wrap a linear layout in myscrollview, I did what's needed in my XML file too but it still cannot scroll horizontally for contents which exceeds the linear layout size. Here is my XML:
<ScrollView
android:id="@+id/scroller"
android:layout_marginTop="16dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup"
android:fadingEdgeLength="5dip"
android:scrollbars="horizontal"
android:overScrollMode="always"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawHorizontalTrack="true"
>
<LinearLayout
android:id="@+id/tracks"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="10dip"/>
</ScrollView >
<ImageView
android:id="@+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_up" />
<ImageView
android:id="@+id/arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/scroller"
android:layout_marginTop="-4dip"
android:src="@drawable/arrow_down" />
</RelativeLayout>
You cannot make a LinearLayout scrollable because it is not a scrollable container. Only scrollable containers such as ScrollView, HorizontalScrollView, ListView, GridView, ExpandableListView can be made scrollable.
Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.
Step 1: Choose your Parent layout. In the example I have choose a LinearLayout with with horizontal orientation. Step 2: Add HorizontalScrollView as a sub-view with layout_width and layout_height as match_parent. You may add padding if you want.
Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.
Please use HorizontalScrollView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With