How to create View partially invisible

前端 未结 1 1599
鱼传尺愫
鱼传尺愫 2021-02-09 21:32

What I\'d like to achieve is effect like the one in the picture: \"enter

So basically ther

1条回答
  •  忘了有多久
    2021-02-09 21:43

    First, create a shape with an alpha gradient. Place the XML into your drawable directory. Let's call it gradient_view.xml

    
    
        
    
    

    Now create a view in your layout to the right of your TextView. You'll need to set width and height appropriately and position in your view as required (RelativeLayout with layout_toTheRightOf would work well).

    
    

    In the right place in your code, animate it. Change the -200 to whatever you need (or even better, find the left X of your gradient view and subtract the left edge of your TextView to find the amount to move).

    TranslationAnimation anim = new TranslateAnimation(0, -200, 0, 0);
    anim.setDuration(1000);
    myTextView.startAnimation(anim);
    

    http://developer.android.com/reference/android/view/animation/TranslateAnimation.html

    There's a bit more work to do but this is most of what you need.

    Good luck

    0 讨论(0)
提交回复
热议问题