如何使渐变完全像android中的drawable一样

时间:2017-08-10 10:07:01

标签: android android-layout android-custom-view drawable android-drawable

注意:更新了问题!

我想制作如图片

中提到的gradiend

pic

居中的灰色是我希望它与左右合并的一条线

已尝试解决方案

Android drawable with background and gradient on the left

我无法找到更多关于我需要的自定义可绘制渐变

 <shape android:shape="rectangle">
        <gradient
            android:angle="0"
            android:centerColor="@color/white"
            android:endColor="@color/gray"
            android:startColor="@color/gray"
            android:type="linear"
            />
 </shape>

我有这两个图像,并希望用drawable来制作它们。

提前感谢..

PS:我也尝试过我的问题,但是我觉得这个渐变是不可能的,我已经等了3个月才能解决。

3 个答案:

答案 0 :(得分:0)

试试这个并改变你想要的颜色

android:background:"@drawable/color_grad"

color_grad.xml
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:centerColor="#FAFAFA"
    android:endColor="#C7C7C7"
    android:startColor="#C7C7C7"
    android:type="linear"
    android:angle="270"/>
<corners android:radius="0dp" />

答案 1 :(得分:0)

android:background="@drawable/gradient"   

 <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:startColor="#C3C3C3"
            android:endColor="#00000000"
            android:angle="45"/>    
    </shape>

答案 2 :(得分:0)

尝试使用type作为radial:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:useLevel="false">
    <size
        android:width="48dip"
        android:height="48dip" />

    <gradient
        android:centerColor="@android:color/white"
        android:centerY="0.5"
        android:gradientRadius="180"
        android:type="radial"
        android:useLevel="false" />
</shape>