Search code examples
androidxmleclipseandroid-scrollview

Android Scroll View is Too Long


I'm super new to Android -

I've dropped in a scrollview on my screen and am just placing some text inside of it. I'm doing this because on some phones the text runs off the screen.

The problem I'm having is that the scrollview I've dropped onto the page is longer than the content it holds -- the more narrow the phone screen is, the longer the 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="wrap_content"
    android:fillViewport="true" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/app_background"
    android:orientation="vertical"
    android:padding="10dp" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="20"
        android:inputType="textMultiLine"
        android:lineSpacingExtra="3dp"
        android:text="Get ready to melt fat and burn calories with Fit Body Boot Camp&apos;s 14 Day Fat Furnace Workout Program! This is a detailed 14 Day Workout plan based on Fit Body Boot Camp&apos;s Unstoppable Fitness Formula that has been implemented in close to 300 boot camps worldwide by hundreds of thousands of clients who made the decision to lose weight and get healthier."
        android:textColor="#FFF"
        android:textColorLink="#FFF"
        android:textSize="20sp" >
    </EditText>

There are some more edittexts after this one, but this is the gist of it. Let me know if you see something stupid.


Solution

  • Your background is in the linear layout that is in the ScrollView. If you put the scroll view in another linear layout that is parent to the ScrollView and contains the background and remove the background from the Linear layout that is a child to the Scroll View the issue will be solved.

    It will look like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:background="@drawable/app_background" >
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >
    
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp" >
    
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="20"
        android:inputType="textMultiLine"
        android:lineSpacingExtra="3dp"
        android:text="THE LONG TEXT YOU'VE TYPED"
        android:textColor="#FFF"
        android:textColorLink="#FFF"
        android:textSize="20sp" >
    </EditText>
    </LinearLayout>
    </ScrollView>
    </LinearLayout>