安卓的LinearGradient XMLLinearGradient、XML

由网友(百年二货)分享简介:我现在面临一个小问题,在XML中的LinearGradient定义。我要的是使用接受的颜色数组和位置数组构造。 这一项:的LinearGradient(浮动X0,Y0浮球,浮球X1,Y1浮动,INT []的色彩,漂浮[]的位置,Shader.TileMode瓦)我如何通过在XML中的数组?下面是XML的梯度定义的例子...

我现在面临一个小问题,在XML中的LinearGradient定义。我要的是使用接受的颜色数组和位置数组构造。

这一项:

 的LinearGradient(浮动X0,Y0浮球,浮球X1,Y1浮动,
INT []的色彩,漂浮[]的位置,Shader.TileMode瓦)
 

我如何通过在XML中的数组?下面是XML的梯度定义的例子,但简单的一

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <梯度
        机器人:startColor =#474946
        机器人:endColor =#181818
        机器人:角=270/>
    <边角机器人:半径=5DP/>
< /形状>
 
linear gradient radical gradient详解

解决方案

您需要做的在Java中code。 ShapeDrawable1.java 从API演示了一个例子。

形状绘制对象详细介绍什么是XML提供

I'm facing a small problem with the LinearGradient definition in XML. What I want is to use the constructor that accepts the array of colors and the array of positions.

This one:

    LinearGradient(float x0, float y0, float x1, float y1, 
int[] colors, float[] positions, Shader.TileMode tile)

How do I pass the array in the XML? Here's the example of XML with gradient definition, but the simple one.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#474946"
        android:endColor="#181818"
        android:angle="270"/>
    <corners android:radius="5dp" />
</shape>

解决方案

You need to do this in Java code. ShapeDrawable1.java from API Demos has an example.

Shape Drawable details what is available in xml.

阅读全文

相关推荐

最新文章