渐变半径为屏幕尺寸的百分比 [英] Gradient Radius as percentage of screen size

查看:226
本文介绍了渐变半径为屏幕尺寸的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个形状绘制径向渐变背景,半径将调整到屏幕尺寸(看看相关的<一个href="http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#attr_android%3agradientRadius">documentation).

I'm trying to create a shape drawable with radial gradient background, with radius that will adjust to the screen size (take a look at the relevant documentation).

这是我的code:

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

    <gradient
        android:endColor="#000"
        android:gradientRadius="50%p"
        android:startColor="#5d2456"
        android:type="radial" />
</shape>

但是好好尝试一下似乎工作。如果我删除%P,它的工作原理,但随后的半径将是静态的,因此不调整屏幕大小......任何想法有什么不对?

But it doens't seem to work. if I remove the "%p", it works, but then the radius will be static, thus not adjusting to the screen size...Any idea what's wrong?

推荐答案

从什么从来就进行试验时,做的工作,但并不如你预期的。
首先

From what I´ve tested, the % does work, but not as you expected.
First of all

android:gradientRadius="50"

好像拿这个值作为像素50像素

seems to take the value as pixels 50px

android:gradientRadius="50%"

转化,就好像50%= 0.5像素,尝试

is converted as if 50% = 0.5 px, try

android:gradientRadius="5000%"

,你会看到一个50像素的半径。
使用%,P 也有类似的结果。显然,这是我希望在未来将被改变,因为它并没有多大用处,因为它是。一般的XML ShapeDrawable资源调整其尺寸,以一些外部容器,在这种情况下,无论 gradientRadius 是设置在容器的大小。

and you will see a 50px radius.
Using %p has a similar result. Obviously this is something I hope will be changed in the future, because it does not have much use as it is. Usually XML ShapeDrawable resources adapt their size to some external container, in this case gradientRadius is setting the size regardless of the container.

这篇关于渐变半径为屏幕尺寸的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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