安卓的LinearGradient XML [英] Android LinearGradient XML

查看:104
本文介绍了安卓的LinearGradient 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/>
< /形状>
 

解决方案

您需要做的在Java中code。 <一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/ShapeDrawable1.html"相对=nofollow> 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.

这篇关于安卓的LinearGradient XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆