Monday, May 25, 2015

How to set a bitmap to RelativeLayout background in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity"
    android:background="@drawable/relative_layout_background"
    >
</RelativeLayout>
res/drawable/relative_layout_background.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
    android:tileMode

        disabled = Do not tile the bitmap. This is the default value.

        clamp = Replicates the edge color.

        repeat = Repeats the bitmap in both direction.

        mirror = Repeats the shader's image horizontally and vertically,
            alternating mirror images so that adjacent images always seam.
-->
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/animal"
    android:tileMode="clamp"
    />
More android examples