Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add scroll bar to the Relative Layout?

I am new to the Android app development. Now I am designing an app, in that I have an Activity which is containing some content but these content is some what more so the content is out of the screen. Now I wanna show that content to the user, but I don't know how to keep scrollers to the Activity.

How to show the total content to the end user with the scroller using RelativeLayout?

like image 546
ram Avatar asked Jan 31 '11 11:01

ram


People also ask

How do I add a scroll to linear layout?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In this above code, we have declare Linear layout as parent and added Vertical Scroll view.

Which layout is used to add scrollbars to a view?

In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it. A ScrollView supports Vertical scrolling only, so in order to create a horizontally scrollable view, HorizontalScrollView is used.

What are the features of relative layout?

RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.


2 Answers

hi see the following sample code of xml file.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/ScrollView01"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <RelativeLayout         android:id="@+id/RelativeLayout01"         android:layout_width="fill_parent"         android:layout_height="fill_parent" >          <LinearLayout             android:id="@+id/LinearLayout01"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:orientation="vertical" >              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>              <TextView                 android:id="@+id/TextView01"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="20dip"                 android:text="@+id/TextView01" >             </TextView>         </LinearLayout>     </RelativeLayout>  </ScrollView> 
like image 54
VenkaReddy Avatar answered Sep 17 '22 21:09

VenkaReddy


Just put yourRelativeLayout inside ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/ScrollView01"     android:layout_width="fill_parent"     android:layout_height="fill_parent">   ------- here RelativeLayout ------ </ScrollView> 
like image 28
Aalkhodiry Avatar answered Sep 21 '22 21:09

Aalkhodiry