So im trying to animate when i set the visibility of a linearlayout with other widgets, from GONE to VISIBLE and the opposite.Im using togglebuttons to show and hide. Here\'s an
Visibility change itself can be easy animated by overriding setVisibility method. Look at complete code:
public class SimpleViewAnimator extends FrameLayout
{
private Animation inAnimation;
private Animation outAnimation;
public SimpleViewAnimator(Context context)
{
super(context);
}
public void setInAnimation(Animation inAnimation)
{
this.inAnimation = inAnimation;
}
public void setOutAnimation(Animation outAnimation)
{
this.outAnimation = outAnimation;
}
@Override
public void setVisibility(int visibility)
{
if (getVisibility() != visibility)
{
if (visibility == VISIBLE)
{
if (inAnimation != null) startAnimation(inAnimation);
}
else if ((visibility == INVISIBLE) || (visibility == GONE))
{
if (outAnimation != null) startAnimation(outAnimation);
}
}
super.setVisibility(visibility);
}
}
You probably want to use an ExpandableListView, a special ListView that allows you to open and close groups.
To animate layout changes, you can add the following attribute to your LinearLayout
android:animateLayoutChanges="true"
and it will animate changes automatically for you.
For information, if android:animateLayoutChanges="true"
is used, then custom animation via anim xml will not work.
Well there is a very easy way, but just setting android:animateLayoutChanges="true"
will not work. You need to enableTransitionType in you activity. Check this link for more info: http://www.thecodecity.com/2018/03/android-animation-on-view-visibility.html
You can use the expandable list view explained in API demos to show groups
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html.
To animate the list items motion, you will have to override the getView method and apply translate animation on each list item. The values for animation depend on the position of each list item. This was something which i tried on a simple list view long time back.
There is no easy way to animate hiding/showing views. You can try method described in following answer: How do I animate View.setVisibility(GONE)