[英]How can I add image from src attribute to gradient.xml file in Android?
I am new to Android and I want to display image with gradient background. 我是Android的新手,我想显示带有渐变背景的图像。 Is it possible to add an image into gradient.xml?
是否可以将图像添加到gradient.xml?
Below is the xml code for this. 下面是用于此目的的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>
Solution: 解:
In your main_activity.xml, 在您的main_activity.xml中,
set the background image for your topmost layout: (Relative or Constraint whatever you are using) 为最顶层的布局设置背景图片:(无论您使用的是相对还是约束)
Then take another layout and give height and width to match_parent and apply the below Gradient to the background of it. 然后采用另一种布局,并为match_parent提供高度和宽度,并将以下Gradient应用于其背景。
Gradient file: 渐变文件:
<?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>
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.