1

How to use Scroll Properly in Android.I have to put some part of my layout into a scroll view .please help me to get this

My XML file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:id="@+id/headerLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:background="@drawable/top_bg" android:orientation="horizontal" > <ImageView android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:onClick="goBack" android:src="@drawable/back_button" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="75dp" android:layout_marginTop="10dp" android:text="Traveller Details" android:textColor="@android:color/white" /> </LinearLayout> <!-- from here i want to put it into a scroll view --> <LinearLayout android:id="@+id/tittleLayout" android:layout_below="@+id/headerLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="5dp" android:orientation="vertical" > <TextView android:id="@+id/TittleTravellerDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:gravity="left" android:text="Traveller Details" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/passengerDetails" android:layout_below="@+id/tittleLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <Spinner android:id="@+id/Tittle" android:layout_width="290dp" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:visibility="gone" android:layout_height="wrap_content"/> <EditText android:id="@+id/firstName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="First Name" /> <EditText android:id="@+id/LastName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="Last Name" /> <ListView android:id="@+id/passengerList" android:layout_width="290dp" android:layout_height="166dp" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:visibility="gone" android:choiceMode="singleChoice" /> </LinearLayout> <LinearLayout android:id="@+id/ContactDetailsLayout" android:layout_below="@+id/passengerDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/TittleContactDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="left" android:text="ContactDetails" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/mobileEmailDetails" android:layout_below="@+id/ContactDetailsLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/mobileNumber" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLength="10" android:maxLines="1" android:inputType="number" android:hint="Mobile No" /> <TextView android:id="@+id/emailid" android:layout_width="284dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:hint="Email ID" /> </LinearLayout> <LinearLayout android:id="@+id/continueBooking" android:layout_below="@+id/mobileEmailDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/continuebooking" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="30dp" android:src="@drawable/searchflight" /> </LinearLayout> <!-- Till here i want to put it into a scroll view --> </RelativeLayout> 
4
  • Did you check the HorizontalScrollView and VerticalScrollView?. You just need to wrap the content that you want to make scrollable into one of these two ScrollView. Commented Aug 22, 2013 at 8:59
  • which part you want to put in scrollview? Commented Aug 22, 2013 at 9:03
  • Just put all you want in a ScrollView into a linear/relative layout, since ScrollView only accept one child. Commented Aug 22, 2013 at 9:05
  • @TarunDroid from passengerDetails layout till end Commented Aug 22, 2013 at 10:35

5 Answers 5

7

You should pass a scrollView only one tag . . .

Like This:

<ScrollView android:id="@+id/scroll_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- from here i want to put it into a scroll view --> <LinearLayout android:id="@+id/tittleLayout" android:layout_below="@+id/headerLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="5dp" android:orientation="vertical" > <TextView android:id="@+id/TittleTravellerDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:gravity="left" android:text="Traveller Details" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/passengerDetails" android:layout_below="@+id/tittleLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <Spinner android:id="@+id/Tittle" android:layout_width="290dp" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:visibility="gone" android:layout_height="wrap_content"/> <EditText android:id="@+id/firstName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="First Name" /> <EditText android:id="@+id/LastName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="Last Name" /> <ListView android:id="@+id/passengerList" android:layout_width="290dp" android:layout_height="166dp" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:visibility="gone" android:choiceMode="singleChoice" /> </LinearLayout> <LinearLayout android:id="@+id/ContactDetailsLayout" android:layout_below="@+id/passengerDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/TittleContactDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="left" android:text="ContactDetails" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/mobileEmailDetails" android:layout_below="@+id/ContactDetailsLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/mobileNumber" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLength="10" android:maxLines="1" android:inputType="number" android:hint="Mobile No" /> <TextView android:id="@+id/emailid" android:layout_width="284dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:hint="Email ID" /> </LinearLayout> <LinearLayout android:id="@+id/continueBooking" android:layout_below="@+id/mobileEmailDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/continuebooking" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="30dp" android:src="@drawable/searchflight" /> </LinearLayout> <!-- Till here i want to put it into a scroll view --> </LinearLayout> </ScrollView> 
Sign up to request clarification or add additional context in comments.

Comments

0

This is the way to add scroll view:

 <ScrollView android:id="@+id/SCROLLER_ID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fillViewport="true"> <com.qualcomm.QCARSamples.VideoPlayback.JustifiedTextView android:id="@+id/text_content" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="20dp" android:layout_marginBottom="80dp" android:layout_below="@id/info_frame_text" android:textColor="#ff000000" android:layout_marginLeft="40dp" android:layout_marginRight="20dp" android:visibility="gone"/> </ScrollView> 

Comments

0

Here is your whole code with scrollview in it:

As there can be only one layout inside the scrollview, you will need to take the whole layout inside one linear layout as below:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:id="@+id/headerLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:background="@drawable/top_bg" android:orientation="horizontal" > <ImageView android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:onClick="goBack" android:src="@drawable/back_button" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="75dp" android:layout_marginTop="10dp" android:text="Traveller Details" android:textColor="@android:color/white" /> </LinearLayout> <!-- from here i want to put it into a scroll view --> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/tittleLayout" android:layout_below="@+id/headerLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="5dp" android:orientation="vertical" > <TextView android:id="@+id/TittleTravellerDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:gravity="left" android:text="Traveller Details" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/passengerDetails" android:layout_below="@+id/tittleLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <Spinner android:id="@+id/Tittle" android:layout_width="290dp" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:visibility="gone" android:layout_height="wrap_content"/> <EditText android:id="@+id/firstName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="First Name" /> <EditText android:id="@+id/LastName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="Last Name" /> <ListView android:id="@+id/passengerList" android:layout_width="290dp" android:layout_height="166dp" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:visibility="gone" android:choiceMode="singleChoice" /> </LinearLayout> <LinearLayout android:id="@+id/ContactDetailsLayout" android:layout_below="@+id/passengerDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/TittleContactDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="left" android:text="ContactDetails" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/mobileEmailDetails" android:layout_below="@+id/ContactDetailsLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/mobileNumber" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLength="10" android:maxLines="1" android:inputType="number" android:hint="Mobile No" /> <TextView android:id="@+id/emailid" android:layout_width="284dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:hint="Email ID" /> </LinearLayout> <LinearLayout android:id="@+id/continueBooking" android:layout_below="@+id/mobileEmailDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/continuebooking" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="30dp" android:src="@drawable/searchflight" /> </LinearLayout> </LinearLayout> </ScrollView> <!-- Till here i want to put it into a scroll view --> </RelativeLayout> 

2 Comments

if the ListView visibility is visible it is not working scroll is not coming properly
from tittleLayout till end i have to put in a scoll view so when i will set the proeprty of ListView to wrap_content complete page will ve visible in scroll
0

Try this, also make sure that android:layout_below is given for ScrollView only Not for views inside ScrollView

 <LinearLayout android:id="@+id/headerLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:background="@drawable/top_bg" android:orientation="horizontal" > <ImageView android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:onClick="goBack" android:src="@drawable/back_button" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="75dp" android:layout_marginTop="10dp" android:text="Traveller Details" android:textColor="@android:color/white" /> </LinearLayout> <!-- from here i want to put it into a scroll view --> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/headerLayout" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:id="@+id/tittleLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="vertical" > <TextView android:id="@+id/TittleTravellerDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:gravity="left" android:text="Traveller Details" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/passengerDetails" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Spinner android:id="@+id/Tittle" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:visibility="gone" /> <EditText android:id="@+id/firstName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:hint="First Name" android:maxLines="1" /> <EditText android:id="@+id/LastName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:hint="Last Name" android:maxLines="1" /> <ListView android:id="@+id/passengerList" android:layout_width="290dp" android:layout_height="166dp" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:choiceMode="singleChoice" android:visibility="gone" /> </LinearLayout> <LinearLayout android:id="@+id/ContactDetailsLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/TittleContactDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="left" android:text="ContactDetails" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/mobileEmailDetails" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/ContactDetailsLayout" android:orientation="vertical" > <EditText android:id="@+id/mobileNumber" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:hint="Mobile No" android:inputType="number" android:maxLength="10" android:maxLines="1" /> <TextView android:id="@+id/emailid" android:layout_width="284dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:hint="Email ID" /> </LinearLayout> <LinearLayout android:id="@+id/continueBooking" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/mobileEmailDetails" android:orientation="vertical" > <ImageView android:id="@+id/continuebooking" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="30dp" android:src="@drawable/searchflight" /> </LinearLayout> </LinearLayout> <!-- Till here i want to put it into a scroll view --> </ScrollView> </RelativeLayout> 

Comments

0

Try this..!

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/headerLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:orientation="horizontal" > <ImageView android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:onClick="goBack" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="75dp" android:layout_marginTop="10dp" android:text="Traveller Details" android:textColor="@android:color/white" /> </LinearLayout> <!-- from here i want to put it into a scroll view --> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:layout_gravity="center" android:layout_below="@+id/headerLayout" android:fillViewport="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:id="@+id/tittleLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="5dp" android:orientation="vertical" > <TextView android:id="@+id/TittleTravellerDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:gravity="left" android:text="Traveller Details" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/passengerDetails" android:layout_below="@+id/tittleLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <Spinner android:id="@+id/Tittle" android:layout_width="290dp" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:visibility="gone" android:layout_height="wrap_content"/> <EditText android:id="@+id/firstName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="First Name" /> <EditText android:id="@+id/LastName" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLines="1" android:hint="Last Name" /> <ListView android:id="@+id/passengerList" android:layout_width="290dp" android:layout_height="166dp" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:visibility="gone" android:choiceMode="singleChoice" /> </LinearLayout> <LinearLayout android:id="@+id/ContactDetailsLayout" android:layout_below="@+id/passengerDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/TittleContactDetails" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="left" android:text="ContactDetails" /> <View android:layout_width="wrap_content" android:layout_height="2dip" android:layout_marginTop="2dp" android:background="#FF909090" /> </LinearLayout> <LinearLayout android:id="@+id/mobileEmailDetails" android:layout_below="@+id/ContactDetailsLayout" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/mobileNumber" android:layout_width="290dp" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" android:maxLength="10" android:maxLines="1" android:inputType="number" android:hint="Mobile No" /> <TextView android:id="@+id/emailid" android:layout_width="284dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginTop="10dp" android:hint="Email ID" /> </LinearLayout> <LinearLayout android:id="@+id/continueBooking" android:layout_below="@+id/mobileEmailDetails" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/continuebooking" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="30dp" android:src="@drawable/ic_launcher" /> </LinearLayout> </LinearLayout> </ScrollView> <!-- Till here i want to put it into a scroll view --> </LinearLayout> 

3 Comments

but when the listview is visible then the scroll view is not working
Yes bcoz...Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. You should NOT do this. Just use a LinearLayout instead. Try this link you can get some idea about listview inside scrollview stackoverflow.com/questions/6210895/…
so how could i do this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.