【问题标题】:How to get gradient effect如何获得渐变效果
【发布时间】:2017-06-13 21:44:57
【问题描述】:

您好,我想知道如何获得像this 这样的背景效果? 不同的联系人连颜色都不一样。

我已经尝试了一些教程。

  1. this
  2. this

和其他人。

但没有得到确切的效果。请帮忙。提前致谢。 :)

【问题讨论】:

  • 或者你可以查看this库。
  • 使用ValueAnimator/ObjectAnimator绘制GradientDrawable(或LinearGradient,如果您需要更多功能)

标签: android android-studio animation gradient


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#3B5998"
        android:endColor="#00000000"
        android:angle="45"/>    
</shape>

然后在你的主 xml 中

 <include
        android:id="@+id/include1"
        layout="@layout/actionbar" />

【讨论】:

    【解决方案2】:

    例如在 XML 中

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:startColor="#2E383E"
            android:endColor="#798B97"
            android:angle="45"/>    
    </shape>
    

    创建一个 TransitionDrawable 以在您用于背景的两个可绘制对象之间进行切换。

    <?xml version="1.0" encoding="UTF-8"?>
    <transition xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- use whatever drawables you want, gradients, shapes etc-->
        <item android:drawable="@drawable/start" />
        <item android:drawable="@drawable/end" />
    </transition>
    

    Transition Drawables in Android

    TransitionDrawable trans = (TransitionDrawable) myLayout.getBackground();
    trans.startTransition(2000);
    

    【讨论】:

      猜你喜欢
      • 2013-11-01
      • 1970-01-01
      • 2017-05-15
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 2012-04-29
      • 1970-01-01
      相关资源
      最近更新 更多