【发布时间】:2015-06-09 19:00:04
【问题描述】:
假设我只想为线性布局的背景着色 64%。我想从左到右给它上色,让它成为纯色。
起初我尝试使用 Gradient Drawables,因为它允许我指定颜色的方向和颜色……但它不允许我指定百分比。如果我可以在 xml drawable 中做到这一点,那将是理想的,但百分比会发生变化,我需要根据百分比重新调整背景。
这是我为整个视图着色的代码。有没有办法只为视图的 35% 而不是整个视图着色?
GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[] {getContext().getResources().getColor(R.color.icitizen_poll_opaque_gold),
getContext().getResources().getColor(R.color.icitizen_poll_opaque_gold)});
gradient.setCornerRadius(1f);
v.setBackground(gradient);
【问题讨论】:
-
你已经很接近了:使用 ClipDrawable 代替 GradientDrawable,忘记下面的答案以及其他视图等......
标签: android view gradient background-color