【问题标题】:How to get a color depends on the percentage calculated如何获得颜色取决于计算的百分比
【发布时间】:2018-06-29 19:17:01
【问题描述】:

我想在它的背景中创建一个带有颜色的组件,该颜色从绿色变为红色...... 好吧,我有一门课程,名额有限,例如 10 个名额 = 100%, 学生可以加入这个课程,所以对于每个学生,我需要计算百分比并使用这个百分比我将组件的颜色更改为 100%,这里组件将具有红色,这意味着没有其他地方

【问题讨论】:

    标签: android colors percentage


    【解决方案1】:

    你需要这样的东西

    private int getcolorPercentage(float percent) {
    
            return (Integer) new ArgbEvaluator().evaluate(percent, 0xff00ff00, 0xffff0000);
        }
    

    用法

    int percent = 10;
    
    view.setBackgroundColor(getcolorPercentage((float)percent/10‌​0));
    

    参考:

    android/animation/ArgbEvaluator

    【讨论】:

    • 谢谢它的工作,但你需要编辑你的答案 view.setBackgroundColor(getcolorPercentage((float)percent/100));
    猜你喜欢
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2013-04-27
    相关资源
    最近更新 更多