<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.tlkg.welcomehome.layoutanimation.MainActivity">
<ListView
android:id="@+id/rootListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
public class MainActivity extends AppCompatActivity {
private String[] arraysRes = {"Layout animation", "Layout animation",
"Layout animation", "Layout animation", "Layout animation", "Layout animation"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView rootListView = (ListView) findViewById(R.id.rootListView);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_expandable_list_item_1, arraysRes);
rootListView.setAdapter(adapter);
AnimationSet set = new AnimationSet(true);
AlphaAnimation aa = new AlphaAnimation(0, 1);
aa.setDuration(2000);
ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, 1f, ScaleAnimation.RELATIVE_TO_SELF, 1f);
sa.setDuration(2000);
set.addAnimation(aa);
set.addAnimation(sa);
LayoutAnimationController lac = new LayoutAnimationController(set, 0.5f);
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
rootListView.setLayoutAnimation(lac);
}
}