2015-12-02 85 views
1

在我的應用程序中,動畫師調整了一些視圖的大小,一切正常,直到出現軟鍵盤。在動畫完成後點擊EditTextEditText的高度恰好在出現軟鍵盤之前返回到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回到其以前的高度。 如何避免這種影響?並使動畫持續/永久?

我發現類似的問題,而不響應Android showing keyboard cancels animation

回答

0

上取View呼叫clearAnimation()你叫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(); 
    } 
} 
+0

我嘗試,但沒有工作。我希望動畫效果是動畫永久性/永久性的。我不明白clearAnimation()可以做到多少? – LunaVulpo

相關問題