view出水面的移动动画

模仿天天果园登录界面的效果。

要点:将要实现动画的TextView被EditText覆盖,

做出出水面,进水面的效果,只要在水面之下看不见,出水面就看得见。

这里写图片描述

布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:text="Hello World!"
        android:textColor="@color/colorAccent"
        android:textSize="25sp" />

    <EditText
        android:id="@+id/et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:background="@color/colorPrimaryDark"
        android:hint="请输入你想输入的"
        android:padding="8dp" />
</FrameLayout>

android:layout_marginTop保证textview的移动空间,

动画:

anim.dismiss.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <translate
        android:duration="100"
        android:fromYDelta="0%"
        android:toYDelta="-100%" />
</set>
anim.show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <translate
        android:duration="100"
        android:fromYDelta="0%"
        android:toYDelta="-100%" />
</set>

MainActivity:

public class MainActivity extends AppCompatActivity {

    private TextView mTv;
    private boolean isShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTv = ((TextView) this.findViewById(R.id.tv));
        EditText mEt = ((EditText) this.findViewById(R.id.et));

        mEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String string = s.toString();
                if (string.length() > 0 && !isShow) {
                    Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.show);
                    mTv.startAnimation(animation); //启动动画
                    animation.setInterpolator(new AccelerateDecelerateInterpolator());
                    isShow = true;
                } else if (string.length() == 0) {
                    Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.dismiss);
                    animation.setInterpolator(new AccelerateDecelerateInterpolator());
                    mTv.startAnimation(animation); //启动动画
                    isShow = false;
                }
            }
        });
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值