Can I adjust (scale) only one component of the Android layout and update the layout during the animation

Imagine that I have a toolbar implemented as a horizontal LinearLayout as follows:

  [___Button1____] [___Button2___] [___Button3___] [___Button4___]

When someone clicks Button2, I want the toolbar to change to:

  [___Button1____] [___________Button2___________] [___Button3___]

The toolbar should transition from the first state to the second state through smooth animation. I would like to use the scale animation on Button2, and although this happens, Button3 and Button 4 should move to the right (while the animation continues). At the end of the animation (or perhaps during) I fade Button4 out.

Question: How to achieve animation of the toolbar layout in such a way that only one component (i.e. Button2) is scaled, while others do not scale - the layout is simply updated during the Button2 animation.

I looked at the LayoutAnimationController, but it doesn’t seem to allow me to: 1. specify different animations for different components, OR 2. indicate that only one component is animated and does not animate the others.

I cannot scale the entire toolbar because it distorts Button1 / 3/4, which I don't want.

Any thoughts on how to do this?

+3
source share
1 answer

I had the same problem with ListView, can you try customizing my code?
Although I'm not sure how you handle button events:

public void onListItemClick(ListView l, View v, int position, long id) 
{
    ImageView iv = (ImageView)v.findViewById(R.id.icon);
    iv.startAnimation(anim);
}

, Button, ImageView.

0

Source: https://habr.com/ru/post/1722444/


All Articles