Say I want to color only 64% of the background of a linearlayout. I want to color it from left to right and have it be a solid color.
At first I tried using Gradient Drawables because it allowed me to specify the orientation of the color, and the color...but it doesn't allow me to specify a %. If I could do this in an xml drawable it would be ideal, but the percents are going to be changing and I need to re-adjust the background based on the %.
Here is my code for coloring the whole view. Is there a way to only color say 35% of the view instead of the whole view?
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);
It's totally possible, few ways to do it, but I would recommend using custom Drawable, for example:
}
...and to use it:
R.id.background is simple LinearLayout with match_parent w/h, It also can be simple View. You should keep xml layout as simple as possible.