I have lot of items on the screen and I need to use the scrollbar so the user can scroll down. However, the scroll is either not visible or it\'s not working. How is it poss
Wrap the linear layout with a <ScrollView>
See here for an example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
</LinearLayout>
Note: fill_parent is deprecated and renamed to match_parent in API Level 8 and higher.
you need to use the following attribute and enclose it within the linear layout
<LinearLayout ...>
<scrollView ...>
</scrollView>
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
Whenever you wanted to make a layout scrollable, you can use <ScrollView>
With a layout or component in it.
This can be done using the tag <ScrollView>
. For ScrollView, one thing you have to remind that, ScrollView must have a single child.
If you want your full layout to be scrollable then add <ScrollView>
at the top. Check the example given below.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
But if you want some part of your layout to be scrollable then add <ScrollView>
within that part. Check the example given below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="400dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
</LinearLayout>
You need to place ScrollView as the first child of Layout file and now put your linearlayout inside it. Now, android will decide on the basis of content and device size available whether to show a scrollable or not.
Make sure linearlayout has no sibling because ScrollView can not have more than one child.