How to create View partially invisible

前端 未结 1 1601
鱼传尺愫
鱼传尺愫 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

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:angle="90"
            android:startColor="#FFFFFFFF"
            android:endColor="#00FFFFFF"
            android:type="linear"/>
    </shape>
    

    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).

    <View android:layout_width="100dp"
        android:layout_height="50dp"
        android:background="@drawable/gradient_view"/>
    

    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)
提交回复
热议问题