Search code examples
androidlayoutscrollview

Fix background image on Scrollview Android


When I use Scrollview in my codes my background image stretches and scrolls with buttons. I want just buttons scroll, not the background. I have attached a related image that you can figure this out. Here is the XML file:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:background="@drawable/back"
                  android:orientation="vertical" >


        <ImageButton
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/app"
                android:layout_gravity="center"
                android:background="@drawable/bluebutton"
                android:layout_marginTop="80dp"
                android:layout_marginRight="80dp"
                android:layout_marginLeft="80dp"

                />

        <ImageButton
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/moshiri"
                android:background="@drawable/bluebutton"
                android:layout_marginTop="8dp"
                android:layout_marginRight="80dp"
                android:layout_marginLeft="80dp"
                />
        <ImageButton
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"

                android:id="@+id/about"
                android:background="@drawable/bluebutton"
                android:layout_marginTop="8dp"
                android:layout_marginRight="80dp"
                android:layout_marginLeft="80dp"
                />
        <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:id="@+id/exit"
                android:background="@drawable/bluebutton"
                android:layout_marginTop="8dp"
                android:layout_marginRight="80dp"
                android:layout_marginLeft="80dp"
                />

    </LinearLayout>
</ScrollView>

enter image description here


Solution

  • Set the background image on the ScrollView and add Padding to the ScrollView or Margins to the Linearlayout.