繁体   English   中英

如何在Android中将src属性中的图像添加到gradient.xml文件?

[英]How can I add image from src attribute to gradient.xml file in Android?

我是Android的新手,我想显示带有渐变背景的图像。 是否可以将图像添加到gradient.xml?

下面是用于此目的的xml代码。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <bitmap android:src="@drawable/bg"/>
    <shape>
        <gradient
            android:startColor="#631f68"
            android:endColor="#ff5555"
            android:angle="45"/>
    </shape>

</item>

解:

在您的main_activity.xml中,

为最顶层的布局设置背景图片:(无论您使用的是相对还是约束)

然后采用另一种布局,并为match_parent提供高度和宽度,并将以下Gradient应用于其背景。

渐变文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="135"
        android:centerColor="@color/colorAccentSecondary"
        android:endColor="@color/colorPrimary"
        android:startColor="@color/colorAccent"
        android:type="linear" />

    <corners android:radius="0dp" />
</shape>

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM