如何制作锐利的渐变画面

时间:2015-12-15 13:42:43

标签: android android-layout drawable

我想制作一个像这样的锐利的黑白渐变 enter image description here

我所做的就是这个

enter image description here

这是我的可绘制文件

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#000"
    android:endColor="#fff"
    android:centerColor="#fff"
    />
</shape>

任何想法如何制作它!

3 个答案:

答案 0 :(得分:2)

有一个很棒的网站,只需去那里,然后换到&#39; android&#39;标签。 这是链接:Angrytools.com

答案 1 :(得分:1)

正如其他人已经注意到的那样,你想要实现的效果不是一个渐变。 如果我了解您正在努力实现灵活图片,以1:1划分

不可能既不通过 .xml 文件也不通过 9patch (然后您将失去黑白之间的明显过渡)。< / p>

首先解决方案是使用LinearLayoutlayout_weight。您可以在布局中添加&#39;&#39; - 如果它是背景 - 在其他组件下。这个&#39;层&#39; 看起来像这样:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@android:color/black"/>

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@android:color/white"/>

</LinearLayout>

如果在布局中使用一次或两次,则此附加/嵌套布局不会有问题,但避免在集合项中使用此类解决方案。

您还可以尝试使用普通的 双色png文件 ImageView。 (提示:此文件的合适尺寸可以为您提供明显的过渡。)

第三种方法,最轻,但耗时一点是覆盖View.onDraw()方法,并在其他内容出现之前画两半绘制。

答案 2 :(得分:0)

首先,根据你的图片,这只包含黑色。所以你可以使用简单的实体来做到这一点 如

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

    <solid android:color="#000000" />

</shape>