問題描述
我面臨一個非常有趣但令人討厭的錯誤,在我的線性布局中,我使用負邊距隱藏了另一個線性布局,當用戶從列表中選擇一種類型時,我使用平移動畫將布局置于前面,錯誤是布局來到前面有一個編輯文本,它變得死了,當我滾動時(我的主要布局被滾動視圖包圍)它變得活躍,當我停止滾動時它又變得死了......我真的無法判斷為什么會發生這種情況,所以伙計們請幫忙....
I am facing a quite interesting but annoying error, in my linear layout i have hided another linear layout using margin in negative and when user selects a type from a list i bring layout to front using Translational Animation the error is that the layout comes to front have an edit text which becomes dead and when i scroll (my main layout is surrounded by scroll view) it comes alive and when i stop scrolling it becomes dead again... i really failed to judge why is this happening so guys plz help....
我還在下面粘貼了視頻鏈接,展示了我的應用程序的這種煩人行為
i have also pasted link of video below showing this annoying behavior of my app
http://www.dailymotion.com/video/xlskk8_android-app-edit-text-error_tech
我在滾動視圖中的布局 xml 是
my layout xml inside scroll view is
<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>
按鈕下方的空線性布局用于動態添加子視圖,所有其他內容均正常執行其功能,只有編輯文本顯示此異常行為.
the empty linear layout below button is used for dynamically adding child views all other things are performing their functionality properly, only the edit text showing this abnormal behavior.
用于動畫的代碼如下
public void animateEditor()
{
slider = new TranslateAnimation(0, 0, 0,180 );
slider.setDuration(1250);
slider.setFillAfter(true);
notes_list.startAnimation(slider);
notes_editor.startAnimation(slider);
}
推薦答案
這里的問題是當應用 slider.setFillAfter(true);
代碼動畫視圖的圖像而不是實際的視圖為什么當我在滑下動畫后看到它們時它們(EditText 和保存按鈕)卡住了,或者你可以說死了而不聽他們的事件,因為實際的視圖在布局后面,而在前面它只是他們的圖像
The problem here was when applying slider.setFillAfter(true);
the code animates the image of Views but not the actual Views that's why when I see them after sliding down animation they were (EditText and save button) stuck or you can say dead and not listening to their events because actual Views were there behind the layout and at front it was just their image
我為該問題找到的解決方案是應用以下代碼:
The solution I found for that problem is to apply following code:
slider.setFillAfter(false);
slider.setFillBefore(false);
// OR you can directly write
slider.setFillEnabled(false);
然后通過設置動畫監聽器并使用以下方法顯示新位置的實際視圖:
And then to show actual views on the new place by setting animation listener and using the following method:
public void onAnimationEnd(Animation a)
使用上述方法在動畫結束時將視圖放置到新位置.這里還有另一個閃爍問題,這是由于 android 動畫偵聽器方法中的問題,即它在實際動畫結束之前被調用并導致閃爍效果,一個棘手的解決方案是將以下代碼行放在第一行public void onAnimationEnd(Animation a)
方法.
Placing the views to new position at the end of animation by using above method. And here still comes another problem of blinking which is due to the problem in android animation listener method which is that it is get called before actually animation ends and causes blinking effect, a tricky solution to it is by putting following line of code at first line of public void onAnimationEnd(Animation a)
method.
// in my case animation applied to notes_editor so the code will be
notes_editor.clearAnimation();
這篇關于EditText 在動畫后卡住并在滾動時重新活著......?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!