Android – xml布局作为背景

前端之家收集整理的这篇文章主要介绍了Android – xml布局作为背景前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以制作由多个图像/比例/对齐组成的xml背景?
因此,有一个复杂的drawable xml可用作 android布局的背景.

例如,这是我想要做的动态xml背景:

因此,对于我的所有不同活动,请将上面的不同布局/视图放在上面:

我知道我不能将布局设置为layout_background,但这里是我想要做的设计(根据之前的图片):

<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>

我看到我们可以将位图设置为可绘制的xml,但是对于缩放和对齐?
有没有更简单的方法来进行这种视觉渲染?

解决方法

您可以在动态xml背景中创建一个布局,并且可以在RelativeLayout之后的所有屏幕中创建 Include
<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 >
原文链接:https://www.f2er.com/android/309329.html

猜你在找的Android相关文章