【问题标题】:how to make gradient exactly like these drawable in android如何在android中使渐变完全像这些drawable
【发布时间】:2017-08-10 10:07:01
【问题描述】:

注意:更新问题!

我想制作图片中提到的渐变

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

已尝试解决方案

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>

我有这两张图片,想用可绘制的..

提前谢谢..

PS:我也尝试了针对我的问题得到的答案,但我认为这种渐变是不可能的,我已经等待了 3 个月的解决方案。

【问题讨论】:

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


【解决方案1】:

尝试将类型用作径向:

<?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>

【讨论】:

  • 身高和体重减少尺寸只有我试过了
  • @AtifAfridi 不是身高和体重,尝试使用 android:type="radial" 。只需将上面的代码粘贴到您的工作室并查看预览。我想这就是你想要的。
  • 我尝试了相同的..但不是我想要的..我想要垂直方向..右n左将是灰色n中心将b白色但与右/左灰色合并但是它垂直制作白线
【解决方案2】:

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

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" />

【讨论】:

  • 还是一样的,我想要0角
  • 尝试改变 endColor 和 startColor
【解决方案3】:
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>

【讨论】:

    猜你喜欢
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2017-08-25
    • 2019-10-04
    相关资源
    最近更新 更多