[ACCEPTED]-How do I add scrollbars to a LinearLayout in Android?-android-linearlayout
You cannot add scrollbars to a LinearLayout
because 11 it is not a scrollable container.
Only scrollable 10 containers such as ScrollView
, HorizontalScrollView
, ListView
, GridView
, ExpandableListView
show scrollbars.
I 9 suggest you place your LinearLayout
inside a ScrollView
which 8 will by default show vertical scrollbars 7 if there is enough content to scroll.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<!-- Your content goes here -->
</LinearLayout>
</ScrollView>
If 6 you want the vertical scrollbar to always 5 be shown, then add android:scrollbarAlwaysDrawVerticalTrack="true"
to your ScrollView
. Note the height 4 of the LinearLayout
is set to wrap_content
- this means the height 3 of the LinearLayout
can be larger than that of the ScrollView
if 2 there is enough content - in that case you 1 will be able to scroll your LinearLayout
up and down.
You can't add a scrollbar to a widget that 3 way. You can wrap your widget inside a ScrollView
. Here's 2 a simple example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txt"/>
</LinearLayout>
</ScrollView>
If you want to do it in 1 code:
ScrollView sv = new ScrollView(this);
//Add your widget as a child of the ScrollView.
sv.addView(wView);
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.