Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a linear layout horizontally scrollable

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>
like image 720
user1654627 Avatar asked Sep 07 '12 11:09

user1654627


People also ask

Can I make a linear layout scrollable?

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.

How do you implement a horizontal scroll?

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.

How can I make my layout scroll both horizontally and vertically?

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.

How do I make a horizontal div scrollable?

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.


1 Answers

Please use HorizontalScrollView

like image 83
Taras Shevchuk Avatar answered Sep 30 '22 09:09

Taras Shevchuk