Is it possible to make a xml background composed of multiple image / scale / alignement? And so to have a complex drawable xml usable as a background for android layout.
For example, this is the dynamic xml background that I would like to do:
And so, for all of my different activities, put my different layouts/views above:
I know I cannot set a layout as a layout_background, but here is the design of what I would like to do (according to previous pictures):
<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 we can set bitmap to drawable xml, but for scale and alignement? Is there an easier way to make this visual rendering?
in your parent layout element, e.g. linearlayout or whatever, simply add android:background="@drawable/background" This will set the background of your layout, assuming you have the image in a /drawable folder.
You can declare a layout in two ways: Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. You can also use Android Studio's Layout Editor to build your XML layout using a drag-and-drop interface.
The Constraint layout is the default layout used in Android.
In Android, for reusing the complete layouts we can use the <include/> and <merge/> tags to embed another layout inside the current layout. Android offers a variety of widgets to provide small and reusable interactive elements.
You can create one Layout as you want in dynamic xml background
and can Include in all screens behind 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 >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With