0

I don't understand why this happend, but I would like to know why and how to solve it. I want my gradient to look like in the Galaxy S7 picture for all devices or different screen sizes

enter image description here

The code for Gradient:

    textView = (TextView) v.findViewById(R.id.fontcolorwhite);

    LinearGradient linearGradient = new LinearGradient(60,-70,60,70, new int[]{Color.parseColor("#00a8d9"), Color.parseColor("#4244b8"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#fde92d"), Color.parseColor("#009e54")},null,
    Shader.TileMode.REPEAT);
    textView.getPaint().setShader(linearGradient);

1 Answers1

0

Allright it now works perfect on all devices and screen size.

The end solution was to use dp instead of pixels and playing around with values till I got the right gradient:

    float px4 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics());
    float px5 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, -17f, getResources().getDisplayMetrics());
    float px6 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics());
    float px7 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18f, getResources().getDisplayMetrics());


    LinearGradient linearGradient = new LinearGradient(px4, px5, px6, px7, new int[]{Color.parseColor("#00a8d9"), Color.parseColor("#4244b8"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#fde92d"), Color.parseColor("#009e54")}, null,
            Shader.TileMode.REPEAT);
    fontcolorpickerbtn.getPaint().setShader(linearGradient);