Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Scrollview stretches background image

So I am trying to make my activity scrollable, and when I put my relativelayout inside a scroll view, this happens:

enter image description here

This is the code for the above screenshot:

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

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background"
        android:orientation="vertical"
        android:paddingLeft="60dp"
        android:paddingTop="53dp" >

        <ImageView
            android:id="@+id/gearImage"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginTop="70dp"
            android:clickable="true"
            android:contentDescription="@string/gearDescription_string"
            android:src="@drawable/gear" />
    </RelativeLayout>

</ScrollView>

If I take out the scrollview, it turns out right, but of course without the scrolling function which I want:

enter image description here

Now, is there any way I can get it to look like this:

enter image description here

So that I can still scroll, but if they reach the bottom of the background image I have, it's just white (hard to tell because the background of the webpage is white, but I added a white rectangle to the bottom of the second image to show what I mean). There wouldn't be a reason for them to reach the bottom anyways.

Of course, if you have any other suggestions as to how I can implement the scrollview without stretching by background image, I would be most delighted to hear about them.

Thank you.

like image 356
capcom Avatar asked Jul 30 '12 16:07

capcom


2 Answers

Check out android:fillViewport. According to the documentation, this defines whether the scrollview should stretch its content to fill the viewport. Add this line of code to your ScrollView:

android:fillViewport="true"

Hope this helps.

EDIT:

Try the following:

  1. on the ScrollView set the android:layout_height="fill_parent"
  2. on the RelativeLayout set the android:layout_height="wrap_content"
like image 168
overbet13 Avatar answered Nov 11 '22 10:11

overbet13


I had same problem, this is worked for me:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rel"  
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:background="@drawable/login_background"
    android:fillViewport="true"
    >

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
   android:orientation="vertical"
  >
like image 24
themaster33 Avatar answered Nov 11 '22 10:11

themaster33