Android线性渐变错误地在中间消失?

时间:2016-12-09 20:54:51

标签: android xamarin

我有一个线性渐变定义为xml中的drawable,具有以下内容:

<?xml version="1.0" encoding="utf-8" ?>

<shape 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
  <gradient
      android:type="linear"
      android:startColor="@android:color/transparent"
      android:centerColor="@color/CenterColor"
      android:endColor="@android:color/transparent"
      android:gradientRadius="100"
      android:centerX="0.5"/>
</shape>

CenterColor定义为#E6E7E8。

我的观点定义为:

<View
  android:id="@+id/addressGradientDivider"
  android:layout_width="match_parent"
  android:layout_height="100dp"
  android:layout_below="@+id/addressTextView"
  android:layout_marginTop="@dimen/NormalVerticalMargin"
  android:layout_marginLeft="@dimen/SmallHorizontalMargin"
  android:layout_marginRight="@dimen/SmallHorizontalMargin"
  android:background="@drawable/DetailsGradientDivider"/>

结果是如下的渐变:

enter image description here

无论出于何种原因,渐变在中间消失,我无法弄清楚原因。我也尝试过以编程方式设置渐变并获得相同的结果。

为什么渐变在中间渐变,如何让渐变的最暗部分位于中心?

1 个答案:

答案 0 :(得分:1)

我认为原因是<input type="text" name="inputtext" id="zoeknaam" /> <select name="searchtype" id="zoektype"><option value="name">name</option><option value="age">age</option></select> <input type="button" id="display" value="Display All Data" /> #00000000是透明的黑色(#000000)而且你的centerColor是非常浅灰色的。 您看到褪色的中心颜色实际上是#E6E7E8。

因此,如果你将这种透明的黑色和非常浅的灰色混合在一起,当alpha不完全为00时,你会看到稍微变暗的灰色。

如果将startColor更改为#00FFFFFF(白色透明),则不会在25%和75%位置看到灰色渐变。虽然,centerColor非常接近白色,所以甚至很难看到渐变。