Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 341
Adama Avatar asked Dec 16 '22 12:12

Adama


2 Answers

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>
like image 159
bochko Avatar answered Dec 30 '22 07:12

bochko


I think scrollview should fill the parent, and children views wrap content since layout_height is the size that the view will actually have on the screen, the scrolling thing happens inside the view

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    //...
    android:layout_height="fill_parent"
    //...
>

EDIT

as pointed out by dbalaouras better use "match_parent" instead of "fill_parent" since the latter is deprecated. The result is the same, just the name has been changed just because "fill" was confusing, if you set that it won't fill the remaining space but just set the dimension according to its parent

like image 35
lelloman Avatar answered Dec 30 '22 09:12

lelloman