如何修复 Android 上可绘制 xml 文件的背景图像?
How to fix background image with drawable xml file on Android?
如何将 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>
您可以直接将drawable定义为layer-list item:
<?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>
可绘制对象将展开以适合您的容器。请注意,我没有修改底部插图 (android:bottom
),以便曲线与容器底部保持齐平。您可以修改 left
、right
、top
和 bottom
属性以获得您想要的曲线。
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"/>
结果
如何将 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>
您可以直接将drawable定义为layer-list item:
<?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>
可绘制对象将展开以适合您的容器。请注意,我没有修改底部插图 (android:bottom
),以便曲线与容器底部保持齐平。您可以修改 left
、right
、top
和 bottom
属性以获得您想要的曲线。
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"/>
结果