Home » Android » android – EditText stucks after animation and alive back on scrolling……?

android – EditText stucks after animation and alive back on scrolling……?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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);
}
How to&Answers:

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();