如何在软键盘似乎避免了动画效果取消? [英] How to avoid cancellation of animator effect when soft keyboard appears?

查看:522
本文介绍了如何在软键盘似乎避免了动画效果取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的一些看法是由动画师调整,一切都OK,直到出现软键盘。当我的动画后的EditText 点击完成的EditText 的高度备份到XML的高度出现软键盘右侧前。

In my app some views are resized by Animator and everything is OK till the soft keyboard appears. When I tap on EditText after animation finish the height of EditText backs to xml height right before the soft keyboard appears.

的细节:
我们说,我们有一个简单的布局有一个按钮和一个文本编辑框:

The details: Let say that we have a simple layout with one button and one text edit box:

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

    <Button
        android:id="@+id/button"
        android:text="start anim"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/text"
        android:layout_below="@id/button"
        android:background="@android:color/holo_blue_bright"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:text="Hello World!" />
</RelativeLayout>

和简单的动画师:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
    android:propertyName="bottom"
    android:duration="500"
    android:valueTo="200dp"
    android:valueFrom="56dp"
    android:repeatCount="0"
    android:valueType="intType"
    />
</set>

然后当上按钮的单击事件我运行动画:

And then when on click event on button I run the animation:

final EditText editText = (EditText) findViewById(R.id.text);
Button button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        AnimatorSet show = (AnimatorSet) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.expand_edit_text);
        show.setTarget(editText);
        show.start();
    }
});

到现在为止就可以了。但当我敲击的EditText 再用软键盘出现的EditText 背对着它的previous高度
如何避免这种效果?而让动画执着/永久的吗?

Till now is OK. But when I tap on EditText and soft keyboard appears then EditText backs to its previous height. How to avoid that effect? And make animation persistent/permanent?

我发现类似的问题没有回应的Andr​​oid键盘显示动画取消

I found similar question without response Android showing keyboard cancels animation

推荐答案

呼叫 clearAnimation()上取查看你叫 startAnimation()

如何检查键盘的可见性:

How to check keyboard visibility:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks whether a hardware keyboard is available
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)
    {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}

这篇关于如何在软键盘似乎避免了动画效果取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆