EditText stucks after animation and alive back on scrolling......?
Asked Answered
S

1

8

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

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.

the code used for animation is below

  public void animateEditor()
{
      slider = new TranslateAnimation(0, 0, 0,180 );   
        slider.setDuration(1250);   
        slider.setFillAfter(true);
        notes_list.startAnimation(slider);
        notes_editor.startAnimation(slider);
}
Staunch answered 19/10, 2011 at 15:46 Comment(0)
S
24

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)

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();
Staunch answered 21/10, 2011 at 7:35 Comment(3)
I am working on dragging and droping I want to sustain that animation till the action down is called but setting fillafter to be false it go back immideately can you help???Mariettemarigold
As i described you have to use animation listener for your animation in which onAnimationEnd(Animation a) method will gets called when your animation ends and at that time you should put your view to the new position where it should be after animation. SetFillAfter(true) means just retain the image of view at the end of animation as during animation its just image of your view which is being animated not the view with complete functionality so the fillafter will place the image of view to new place but not its touch boundsStaunch
This almost worked for me, but still had the occasional flicker, especially on older Android OS. I found that by delaying the updates to the layout it solved the problem. i.e. use a layout.post(Runnable) construct.Holdup

© 2022 - 2024 — McMap. All rights reserved.