【问题标题】:How to create multi color gradient drawable with percent per color and custom angle of gradient如何使用每种颜色的百分比和自定义渐变角度创建可绘制的多色渐变
【发布时间】:2019-07-18 02:36:21
【问题描述】:

例如我有这个来自 CSS 的块:

.Rectangle {
  width: 1000px;
  height: 500px;
  background-image: linear-gradient(60deg, #101010 30%, #151515 20%, #000000);
}

我怎样才能在android上制作它? 还有一件事。 GradientDrawable 中的角度值始终为 45*x。我怎样才能把它放在“60”?

<gradient android:angle="45"
              android:startColor="#101010"
              android:centerColor="#151515"
              android:endColor="#000000"
              android:centerX="0.35"
              android:centerY="1"/>

【问题讨论】:

标签: android android-drawable linear-gradients


【解决方案1】:

1 创建名称为 rectangle.xml 的可绘制文件。

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
    <stroke android:width="2dp" android:color="#ff207d94" />
    <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />
    <corners android:radius="5dp" />
    <gradient android:angle="45"
        android:startColor="#101010"
        android:centerColor="#bc6767"
        android:endColor="#4068ec"
        android:centerX="0.35"
        android:centerY="1"/>
</shape>

在你的 activity.xml 中添加 ImageView TAG

<ImageView
                    android:id="@+id/et_age"
                    android:layout_width="100dp"
                    android:layout_height="32dp"
                    android:hint="YEAR"
                    android:src="@drawable/rectangle"
                    android:background="@drawable/rec"
                    android:textAlignment="center"
                    android:inputType="number"
                    android:textColor="#000" />

【讨论】:

  • 非常感谢。但我不认为 android:centerX="0.35" 可以解决 "#101010 30%, #151515 20%, #000000"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多