Android - xml layout as background

Is it possible to create an xml background consisting of several images / scaling / alignment? And therefore have a complex flexible xml that can be used as the background for the Android layout.

For example, this is a dynamic xml background that I would like to do: enter image description here

So, for all my various activities, put my different layouts / views above: enter image description here

I know that I can’t set the layout as layout_background, but here is the design of what I would like to do (according to previous shots):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background_image" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/main_image" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2" > <ImageView android:layout_width="wrap_content" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:src="@drawable/footer_image" /> </RelativeLayout> </LinearLayout> </RelativeLayout> 

I saw that we can set bitmap to drawable xml, but for scaling and alignment? Is there an easier way to do this visual rendering?

+4
source share
2 answers

You can create one layout as you want in the dynamic xml background and Enable on all screens behind the RelativeLayout , like this

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/app_bg" android:gravity="center_horizontal"> <include layout="@layout/my_dynamic_layout"/> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > ...Your layout code ... </RelativeLayout > </RelativeLayout > 
+7
source

I am quite sure what your requirement is. Assuming you want to put some XML files with different images in one XML file, I give my answer.

Create 3 layouts according to your requirement, and then create the main layout where you want to place these 3 layouts.

-

  • Example: suppose you have

one.xml

two.xml

three.xml

and let's assume that you applied the background of your choice according to your requirements to all of the above layouts

now in main.xml

 < LinearLayout --- ---> < include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/one.xml" /> < include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/two.xml" /> < include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/3.xml" /> < /LinearLayout> 

arrange the layout according to your requirement, and if you need to separate these layouts with some percentage of usage weight = ". 50"

Hope this works for you.

0
source

All Articles