Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my layout able to scroll down?

Tags:

android

layout

I can not scroll down the screen to view the data in the "Replied By:" section. How can I make my layout scrollable?

alt text

like image 697
Prateek Raj Avatar asked Sep 29 '10 06:09

Prateek Raj


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 I make my apps vertically scrollable?

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.


2 Answers

Just wrap all that inside a ScrollView:

<?xml version="1.0" encoding="utf-8"?> <ScrollView   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="fill_parent"   android:layout_height="fill_parent">     <!-- Here you put the rest of your current view--> </ScrollView> 

As David Hedlund said, ScrollView can contain just one item... so if you had something like this:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="fill_parent"   android:layout_height="fill_parent">     <!-- bla bla bla--> </LinearLayout> 

You must change it to:

<?xml version="1.0" encoding="utf-8"?> <ScrollView   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="fill_parent"   android:layout_height="fill_parent">     <LinearLayout       android:layout_width="fill_parent"       android:layout_height="fill_parent">         <!-- bla bla bla-->     </LinearLayout> </ScrollView> 
like image 138
Cristian Avatar answered Sep 28 '22 01:09

Cristian


For using scroll view along with Relative layout :

<ScrollView     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen -->      <RelativeLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:paddingBottom="@dimen/activity_vertical_margin"         android:paddingLeft="@dimen/activity_horizontal_margin"         android:paddingRight="@dimen/activity_horizontal_margin"         android:paddingTop="@dimen/activity_vertical_margin"         android:background="@drawable/background_image"     >      <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. -->     </RelativeLayout> </ScrollView> 
like image 29
Vinil Narang Avatar answered Sep 28 '22 00:09

Vinil Narang