Saturday, July 22, 2017

Android development - Adding scrollbar in your activity

Adding scroll bar in your activity in your mobile application can be done easily.

e.g. You have main layout for your mobile application as below

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    tools:context="com.learning.course.letslearn.MainMenu"    android:orientation="vertical"    android:layout_weight="100"    android:layout_marginLeft="15dp"    android:layout_marginRight="15dp"    android:layout_marginTop="15dp"    >
.............
.............
.............
</LinearLayout>

Enclosing this with scroll view will ensure that whenever screen have less vertical space an scroll bar will be displayed

xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/ScrollView01"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:fillViewport="true"    android:layout_marginBottom="10dp"    >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    tools:context="com.learning.course.letslearn.MainMenu"    android:orientation="vertical"    android:layout_weight="100"    android:layout_marginLeft="15dp"    android:layout_marginRight="15dp"    android:layout_marginTop="15dp"    >
.............
.............
.............
</LinearLayout>
</ScrollView>

No comments:

Post a Comment