【问题标题】:How to fix background image with drawable xml file on Android?如何在 Android 上使用可绘制的 xml 文件修复背景图像?
【发布时间】:2019-05-29 23:52:00
【问题描述】:

如何将this picture 制作成android drawable.xml 格式?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:src="@drawable/wallpaper"></bitmap>
    </item>
</layer-list>

【问题讨论】:

标签: android xml drawable


【解决方案1】:

drawable 将展开以适合您的容器。请注意,我没有修改底部插图 (android:bottom),以便曲线与容器底部保持齐平。您可以修改leftrighttopbottom 属性以获得您想要的曲线。

rounded_header.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="-100dp"
        android:left="-400dp"
        android:right="-400dp">
        <shape android:shape="oval">
            <gradient
                android:startColor="#F07B26"
                android:endColor="#F8BA4C"/>
        </shape>
    </item>
</layer-list>

layout.xml

<View
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@drawable/rounded_header"/>

结果

【讨论】:

    【解决方案2】:

    您可以直接将drawable定义为图层列表项:

        <?xml version="1.0" encoding="utf-8"?>
        <layer-list 
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:opacity="opaque">
    
        <!-- The background color, preferably the same as your normal theme -->
        <item android:drawable="@drawable/wallpaper"/>
    
        </layer-list>
    

    【讨论】:

    • 我不想使用drawable文件夹中的图片。如何在 xml 中制作这些图像?我想使用 xml 绘制形状。谢谢。
    • 我想用可绘制文件夹在 xml 中创建壁纸文件
    猜你喜欢
    • 2013-09-18
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多