2011-10-19 57 views
8

我正面臨一個相當有趣但令人討厭的錯誤,在我的線性佈局中,我隱藏了另一個使用負值的邊界線性佈局,當用戶從列表中選擇一種類型時,我使用Translational Animation將佈局帶到前端,錯誤在於佈局前面有一個編輯文本變成死了,當我滾動(我的主要佈局是由滾動視圖包圍)它來活着,當我停止滾動它變得死了再次...我真的不能判斷爲什麼會發生這樣的傢伙PLZ幫助....EditText在動畫和動態回滾滾動後卡住......?

我也粘貼下面顯示我的應用程序的這種令人討厭的行爲視頻的鏈接

http://www.dailymotion.com/video/xlskk8_android-app-edit-text-error_tech

滾動視圖裏面

我的佈局XML是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dip" 
android:layout_marginRight="10dip" 
android:layout_marginTop="-110dip" 
android:layout_marginBottom="5dip" 
android:id="@+id/notes_editor" 
android:orientation="vertical" 
> 
<EditText 
android:id="@+id/enter_note" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:maxLines="2" 
android:lines="2"> 
</EditText> 
<Button 
android:id="@+id/save_note" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="Save" /> 

</LinearLayout> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="-10dip" 
android:id="@+id/notes_list" 
android:orientation="vertical" 
> 
</LinearLayout> 

</LinearLayout> 

下面的按鈕空的線性佈局用於動態添加子視圖所有其他的事情都是正確執行其功能,僅表示該異常行爲的編輯文本。

用於動畫的代碼如下

public void animateEditor() 
{ 
     slider = new TranslateAnimation(0, 0, 0,180); 
     slider.setDuration(1250); 
     slider.setFillAfter(true); 
     notes_list.startAnimation(slider); 
     notes_editor.startAnimation(slider); 
} 

回答

23

這裏的問題是應用slider.setFillAfter(true);當代碼動畫瀏覽的圖像,但不是實際的意見,這就是爲什麼當我滑下動畫完成後,看到他們,他們( EditText和保存按鈕)卡住,或者你可以說死了,沒有聽他們的事件,因爲實際的意見是在佈局後面,在前面,這只是他們的形象

我發現這個問題的解決方案是應用以下代碼:

slider.setFillAfter(false); 
slider.setFillBefore(false); 
// OR you can directly write 
slider.setFillEnabled(false); 

然後通過設置動畫監聽和通過以下的方法,以顯示在新的地點實際的觀點:

public void onAnimationEnd(Animation a) 

通過使用上述方法放置視圖來在動畫結束新位置。這裏還有另一個閃爍的問題,這是由於android動畫偵聽器方法中的問題引起的,它是在實際動畫結束並被引起閃爍效果之前被調用的,一個棘手的解決方案是通過在第一行放置以下代碼行的public void onAnimationEnd(Animation a)方法。

// in my case animation applied to notes_editor so the code will be 
notes_editor.clearAnimation(); 
+0

我正在拖動和拖放我想維持該動畫,直到行動下來被稱爲,但設置fillafter是假的,它會立即回來,你可以幫助嗎? –

+0

正如我所描述的,您必須爲您的動畫使用動畫偵聽器,其中onAnimationEnd(Animation a)方法將在動畫結束時調用,並且當時您應該將視圖放置到應該在動畫之後的新位置。 SetFillAfter(true)意味着只在動畫結束時保留視圖圖像,而不是動畫中的視圖的正常圖像,而不是具有完整功能的視圖,因此fillafter會將視圖圖像放置到新的位置,而不是其視圖的圖像觸摸邊界 –

+0

這幾乎爲我工作,但仍然偶爾閃爍,特別是在較舊的Android操作系統。我發現通過延遲佈局更新解決了問題。即使用layout.post(Runnable)構造。 –