So I am trying to make my activity scrollable, and when I put my relativelayout inside a scroll view, this happens:
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:
Now, is there any way I can get it to look like this:
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.
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.
Try the following:
ScrollView
set the android:layout_height="fill_parent"
RelativeLayout
set the android:layout_height="wrap_content"
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"
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With