0

I have to make a TextView that disappears progressively related to his Y coordinate (in a ScrollView). The text should disappear progressively.

This means that the top of the letter (in the TextView) should have an alpha 0 and the bottom (of the same letter) should have an alpha 1.

I have to do this in my CustomeView, that is in a ScrollView. And make the textDisepear related to the scroll.

So how can i do this?

is this possible with a brush?

i have an image example:

enter image description here

i hope you'll be able to understand my problem..

  • I think this is the best answer to your question: http://stackoverflow.com/questions/2680607/text-with-gradient-in-android – user2696372 May 14 '14 at 19:05

1 Answers1

0

You can use a Shader for that:

Shader alphaShader = new LinearGradient(0, 0, 0, textHeight,
        new int[] {Color.parseColor("#ff000000"), Color.parseColor("#00000000")},
        new float[] {0, 1}, TileMode.CLAMP);
textView.getPaint().setShader(alphaShader);
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
  • Ok, thanks And can i use this with a RelativeLayout / LinearLayout / View / MyCustomeView ? – Pierre-Emmanuel Mercier May 14 '14 at 23:31
  • You can, but for a layout it will only work on it's background -- because it only works on stuff that the `View` draws itself. To fade children of a `RelativeLayout` this way, you'll need to assign a shader to each one of them, and tweak parameters based on their position. Also, if you're just looking to fade the topmost and lowest element edges in something scrollable, look into `android:fadingEdge` and `android:requiresFadingEdge` attributes – Ivan Bartsov May 15 '14 at 04:03