Saturday, 9 February 2019

Animation for some layout in an inflated row in a listview

There is a listview with inflated rows. At each row, there is a button called btn_to_show_actual to show the hidden relativelayout ll_hide_btn (a layout containing several buttons) from outside the right of the screen into the screen (at the same Y location) of its parent row.

 X_in_screen = Constants.SCREEN_W * 1/2 ; 
 X_out_screen = Constants.SCREEN_W 
 Y_in_screen = Constants.SCREEN_H /2;

The above are checked with proper figures.

Codes are as follows:

Layout for each inflated row in the listview:

<ImageButton
    android:id="@+id/btn_to_show_actual"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:background="@null"
    android:src="@drawable/btn_to_show_actual_selector"
    android:scaleType="fitXY"/>

<RelativeLayout
    android:id="@+id/ll_hide_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/btn_to_show_actual"
    android:layout_alignBottom="@+id/btn_to_show_actual"
    android:layout_toLeftOf="@+id/btn_to_show_actual"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/btn_to_show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/btn_delete"
        android:background="@null"
        android:src="@drawable/btn_left_selector"
        android:scaleType="fitXY"/>

    <ImageButton
        android:id="@+id/btn_to_hide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/btn_delete"
        android:background="@null"
        android:src="@drawable/btn_right_selector"
        android:scaleType="fitXY"/>

    <ImageButton
        android:id="@+id/btn_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/btn_amend"
        android:background="@null"
        android:src="@drawable/btn_delete_selector"
        android:scaleType="fitXY"/>

    <ImageButton
        android:id="@+id/btn_amend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/btn_share"
        android:background="@null"
        android:src="@drawable/btn_input_selector"
        android:scaleType="fitXY"/>

    <ImageButton
        android:id="@+id/btn_share"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:src="@drawable/btn_share2_selector"
        android:scaleType="fitXY"/>


</RelativeLayout>

Code:

btn_to_show_actual.setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View v) {
                        Utilities.system_toast(Show_database.this, "btn to show actual pressed" + "\n" + "X-screen=" + Constants.SCREEN_W + "; X-in=" + X_in_screen + "; X-out= " + X_out_screen + "; Y=" + Y_in_screen);

                        //btn_to_show_actual.setVisibility(View.INVISIBLE);
                        btn_to_show.setVisibility(View.VISIBLE);

                        translate_to_left =  new TranslateAnimation(Animation.ABSOLUTE, X_out_screen,                   // from X0
                                Animation.ABSOLUTE, X_in_screen,        // to X1
                                Animation.ABSOLUTE, Y_in_screen,        // from Y0
                                Animation.ABSOLUTE, Y_in_screen);       // to Y1
                        translate_to_left.setInterpolator(new DecelerateInterpolator());
                        translate_to_left.setDuration(800);
                        translate_to_left.setFillAfter(true);
                        translate_to_left.setAnimationListener(new Animation.AnimationListener() {
                            public void onAnimationStart(Animation a) {
                            }
                            public void onAnimationRepeat(Animation a) {}
                            public void onAnimationEnd(Animation a)
                            {
                                btn_to_hide.setVisibility(View.VISIBLE);
                                btn_to_show.setVisibility(View.INVISIBLE);
                            }
                        });

                        ll_hide_btn.startAnimation(translate_to_left);
                    }
                });

                btn_to_hide.setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View v)
                    {
                        Utilities.system_toast(Show_database.this, "btn to hide pressed");

                        translate_to_right =  new TranslateAnimation(Animation.ABSOLUTE, X_in_screen,               // from X0
                                Animation.ABSOLUTE, X_out_screen,           // to X1
                                Animation.ABSOLUTE, Y_in_screen,            // from Y0
                                Animation.ABSOLUTE, Y_in_screen);           // to Y1
                        translate_to_right.setInterpolator(new DecelerateInterpolator());
                        translate_to_right.setDuration(800);
                        translate_to_right.setFillAfter(true);
                        translate_to_right.setAnimationListener(new Animation.AnimationListener() {
                            public void onAnimationStart(Animation a) {
                            }
                            public void onAnimationRepeat(Animation a) {}
                            public void onAnimationEnd(Animation a)
                            {
                                btn_to_hide.setVisibility(View.INVISIBLE);
                                btn_to_show.setVisibility(View.VISIBLE);
                                btn_to_show_actual.setVisibility(View.VISIBLE);
                            }
                        });

                        ll_hide_btn.startAnimation(translate_to_right);
                    }
                });

Question:

After pressing the btn_to_show_actual, the ll_hide_btn cannot translate from outside the screen into screen. How can I make the ll_hide_btn show / go away and translate properly?



from Animation for some layout in an inflated row in a listview

No comments:

Post a Comment