在Android Studio中更改日出背景的渐变颜色位置。

huangapple go评论70阅读模式
英文:

Changing gradient colour positions for sunrise background in Android studio

问题

我在Android Studio中对梯度有一个问题。我想为我的应用程序制作一个日出背景,我可以使用以下xml创建一个类似下面这样的基本渐变:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient android:startColor="@color/sunriseblue"
    android:centerColor="@color/sunrisePink"
    android:endColor="@color/sunriseYellow"></gradient>

</shape>

这会创建一个背景渐变,其中每种颜色均等地占据渐变的三分之一。

我现在想知道如何修改渐变中各个颜色的位置,以使背景看起来像这样:

期望的背景

因此,大部分屏幕是黄色的,顶部几乎没有蓝色。谢谢!

英文:

I have a question on gradients with Android Studio. I want to make a sunrise background for my app and I am able to make a basic gradient like the one below using the following xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;shape xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:shape=&quot;rectangle&quot;&gt;

&lt;gradient android:startColor=&quot;@color/sunriseblue&quot;
    android:centerColor=&quot;@color/sunrisePink&quot;
    android:endColor=&quot;@color/sunriseYellow&quot;&gt;&lt;/gradient&gt;

&lt;/shape&gt;

This creates a background gradient where each colour equally occupies a third of the gradient.

I am now wondering how I can modify the positions of the individual colours in the gradient such that I can make the background like this:

desired background

So the majority of the screen is yellow and there is very little blue at the top. Thanks!

答案1

得分: 0

你可以使用android:centerX来更改中间颜色的中心位置。

英文:

You can use android:centerX to change the center position of your middle color

答案2

得分: 0

将中心颜色设置为与主导颜色更相似。另外,使用 centerY 控制中心颜色位置:

	<gradient
	    	android:centerY="25%"
	    	android:startColor="#FF315963"
	    	android:centerColor="#FFEAA55C"
	    	android:endColor="#FFEAD05C"/>

这是结果:

在Android Studio中更改日出背景的渐变颜色位置。

英文:

Set the center color to be more similar to the predominant one. In addition, use the centerY to control the center color position:

	&lt;gradient
	    	android:centerY=&quot;25%&quot;
	    	android:startColor=&quot;#FF315963&quot;
	    	android:centerColor=&quot;#FFEAA55C&quot;
	    	android:endColor=&quot;#FFEAD05C&quot;/&gt;

This is the result:

在Android Studio中更改日出背景的渐变颜色位置。

huangapple
  • 本文由 发表于 2020年9月27日 00:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64080353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定