Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale background image in LinearLayout

Tags:

android

layout

I'm having the following problem;

I have a LinearLayout with in it a ScrollView, in the ScrollView is some custom view. Now I want to put an image in the background of the LinearLayout and keep the image in its original size. But when I set the background property of the LinearLayout it stretches to fit the full screen. How can I make it so that the image keeps its original size?

My xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/some_drawable">
  <ScrollView
    android:id="@+id/scrollview"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:fillViewport="true">
    <some.custom.layout
        android:id="@+id/mainLayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        />
  </ScrollView>
</LinearLayout>
like image 572
Joris Avatar asked Apr 29 '11 15:04

Joris


1 Answers

Code example for Egor's answer:

<FrameLayout
    android:id="@+id/FrameLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    >

    <ImageView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/background"
        />

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

    </LinearLayout>

</FrameLayout>
like image 165
Asaf Pinhassi Avatar answered Sep 17 '22 11:09

Asaf Pinhassi