How to add a background image to an action?

using a theme or imageview?

+63
android image background
Jul 22 '10 at 8:39
source share
6 answers

use the android:background attribute in your xml. The easiest way if you want to apply it to an entire action is to put it in the root of your layout. Therefore, if you have a RelativeLayout as the start of your xml, enter it here:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootRL" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background"> </RelativeLayout> 
+106
Jul 22 '10 at 8:44
source share
โ€” -

You can set the โ€œbackground imageโ€ to action by setting the android:background xml attributes as follows:

(Here, for example, take LinearLayout for activity and set the background image for the layout (i.e. indirectly for activity))

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/icon"> </LinearLayout> 
+13
Jul 22 '10 at 8:53
source share

Put the image in a drawable folder. the dropdown folder is in res. 5 options are available draw-HDI draw-ldpi draw-MDPI draw-xhdpi hood-xxhdpi

+2
Apr 30 '14 at 9:53
source share

Currently, we should use match_parent :

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/background"> </RelativeLayout> 

enter image description here

+1
Apr 05 '16 at 18:12
source share

We can easily put a background image in a PercentFrameLayout using ImageView. We need to set the attribute value scaleType = "fitXY", and in the foreground we can also display another view, for example textview or button.

  <android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" > <ImageView android:src="@drawable/logo" android:id="@+id/im1" android:scaleType="fitXY" android:layout_height="match_parent" android:layout_width="match_parent"/> <EditText android:layout_gravity="center_horizontal" android:hint="Enter Username" android:id="@+id/et1" android:layout_height="wrap_content" app:layout_widthPercent="50%" app:layout_marginTopPercent="30%" /> <Button android:layout_gravity="center_horizontal" android:text="Login" android:id="@+id/b1" android:layout_height="wrap_content" app:layout_widthPercent="50%" app:layout_marginTopPercent="40%"/> </android.support.percent.PercentFrameLayout> 
+1
May 20 '17 at 9:42 a.m.
source share

and do not forget to clean your project after writing these lines, you will get an error in your XML file until you clean your project in eclipse: Project-> Clean ...

0
Sep 01 '13 at 11:58 on
source share



All Articles