0

I am trying to make the screen which fits great on a vertical orientation scroll for a horizontal as it does not fit and does not scroll. I added a scroll view with the single child of linear layout and the views I want inside that. No errors but it still does not scroll when I turn the phone to a horizontal orientation. What am I doing wrong? below is my XML

Thanks

<TextView android:text="test App" android:textSize="20dp" android:layout_gravity="center_horizontal" android:textColor="#FCFCFC" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <TextView android:text="" android:textSize="20dp" android:layout_gravity="center_horizontal" android:textColor="#FCFCFC" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <ScrollView android:layout_width="match_parent" android:layout_height="400dp" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="Last Name" android:textSize="15dp" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" ></TextView> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="wrap_content" android:text="" android:singleLine="true" ></EditText> <TextView android:text="" android:textSize="10dp" android:layout_gravity="center_horizontal" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <TextView android:text="First Name" android:textSize="15dp" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" ></TextView> <EditText android:layout_width="fill_parent" android:id="@+id/editText2" android:layout_height="wrap_content" android:text="" android:textSize="20dp" android:singleLine="true" ></EditText> <TextView android:layout_gravity="center_horizontal" android:text="" android:textSize="15dp" android:layout_width="wrap_content" android:id="@+id/TextView01" android:layout_height="wrap_content" ></TextView> <TextView android:text="Description" android:textSize="15dp" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" ></TextView> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="wrap_content" android:text="" android:textSize="15dp" android:singleLine="false" android:lines="10" ></EditText> </LinearLayout> </ScrollView> <TextView android:layout_gravity="center_horizontal" android:text="" android:id="@+id/TextView02" android:textColor="#FCFCFC" android:textSize="5dp" android:layout_height="wrap_content" android:layout_width="wrap_content" ></TextView> <Button android:text="Next" android:textSize="20dp" android:layout_gravity="center_horizontal" android:id="@+id/nextpage" android:layout_width="150dp" android:layout_height="60dp" android:layout_alignParentBottom="true" ></Button> 

1
  • remove the dang "400dp" defined height on the scroll view. make it match_parent. Commented Apr 29, 2011 at 21:37

5 Answers 5

1

Your ScrollView and it's contents are always the same size. The view layout doesn't pay attention to whether or not it's visible on screen. Currently, the last TextView and Button in your layout are probably also hidden in lanscape mode (I'm assuming all this is wrapped in a root LinearLayout since the root tag is missing). The ScrollView simply says, "if my contents are larger then I am, I will scroll them".

You should consider a layout where your top elements hang to the top, your bottom two elements hang to the bottom, and the scrollview fills the space in between. That way, when it comes to landscape the view will be smaller, and the contents will start scrolling within.

Here's what I THINK you want :)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- Top Elements --> <TextView android:text="test App" android:textSize="20dp" android:layout_gravity="center_horizontal" android:textColor="#FCFCFC" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="" android:textSize="20dp" android:layout_gravity="center_horizontal" android:textColor="#FCFCFC" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textView1" /> <!-- Bottom Elements --> <Button android:text="Next" android:textSize="20dp" android:layout_gravity="center_horizontal" android:id="@+id/nextpage" android:layout_width="150dp" android:layout_height="60dp" android:layout_alignParentBottom="true" /> <TextView android:layout_gravity="center_horizontal" android:text="" android:id="@+id/TextView02" android:textColor="#FCFCFC" android:textSize="5dp" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_above="@id/nextpage" /> <ScrollView android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_below="@id/textView3" android:layout_above="@id/TextView02"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="Last Name" android:textSize="15dp" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" /> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="wrap_content" android:text="" android:singleLine="true" /> <TextView android:text="" android:textSize="10dp" android:layout_gravity="center_horizontal" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="First Name" android:textSize="15dp" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" /> <EditText android:layout_width="fill_parent" android:id="@+id/editText2" android:layout_height="wrap_content" android:text="" android:textSize="20dp" android:singleLine="true" /> <TextView android:layout_gravity="center_horizontal" android:text="" android:textSize="15dp" android:layout_width="wrap_content" android:id="@+id/TextView01" android:layout_height="wrap_content" /> <TextView android:text="Description" android:textSize="15dp" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FCFCFC" android:singleLine="true" /> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="wrap_content" android:text="" android:textSize="15dp" android:singleLine="false" android:lines="10" /> </LinearLayout> </ScrollView> </RelativeLayout> 

I don't believe your 400dp height is necessary in this case, because the bottom elements will hang to the bottom of the screen instead of you needing a fixed height to space them out. However, if it is still relevant put it on the LinearLayout inside the ScrollView, not the ScrollView itself. This is the whole layout, BTW. Not to be inserted inside anything.

If that's not exactly what you are looking for, hopefully it puts you on the right path :)

Hope that Helps!

Sign up to request clarification or add additional context in comments.

1 Comment

That is what I am trying to do. But it is not working when I turn the phone. Contents that are off screen stay there and I cannot scroll
0

Are you trying to scroll the ScrollView horizontally? According to the API (http://developer.android.com/reference/android/widget/ScrollView.html) ScrollViews only work vertically. You'd likely have to write your own implementation of ScrollView that scrolls horizontally.

3 Comments

It seems like something that should happen automatically. My layout fits vertically but is too long when I turn the phone. I just want it to scroll as I have a button at the bottom of the layout. Now I have to write a bunch of code to do that? Doesn't seem right.
Forgot HorizontalScrollView existed, silly me. I'm still a little confused though. You say you have a button at the bottom... do you want to have a vertical scroll when your phone is in landscape?
You may want to try changing the height of your LinearLayout to WRAP_CONTENT. As it is right now, it would be matching the height of the ScrollView, which would not leave enough room to show everything in the LinearLayout.
0

You have to use HorizontalScrollView for horizontal scrolling

1 Comment

I thought that was too make the screen scroll horizontally. I want it to scroll vertically when the phone is oriented horizontally.
0
 <ScrollView android:id="@+id/scrllvwNo1" android:layout_height="wrap_content" android:layout_width="wrap_content"> <HorizontalScrollView android:layout_height="wrap_content" android:layout_width="wrap_content"> <TextView android:id="@+id/text" android:text="your text" android:gravity="center" android:background="#0000aa" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </HorizontalScrollView> </ScrollView> 

Comments

0

I think what you're looking for is the android:isScrollContainer xml element. Set this to true and define your scrollbars in android:scrollbars and android:scrollbarStyle. The developer docs say this is to accomodate IME's but I've found it works for more than just that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.