软键盘出现时如何避免取消动画效果?
在我的应用程序中,一些视图由Animator调整大小,一切正常,直到出现软键盘。 当动画结束后点击EditText
在出现软键盘之前EditText
的高度返回到xml高度。
细节:假设我们有一个按钮和一个文本编辑框的简单布局:
<?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>
然后当点击按钮上的事件时,我运行动画:
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
回EditText
之前的高度 。 如何避免这种影响? 并使动画持续/永久?
我发现类似的问题没有反应Android显示键盘取消动画
调用clearAnimation()
,无论哪个View
调用startAnimation()
。
如何检查键盘可见性:
@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();
}
}
链接地址: http://www.djcxy.com/p/93431.html
上一篇: How to avoid cancellation of animator effect when soft keyboard appears?