1. By default, the subview added to viewgrop is displayed directly. There is a relatively simple way to add an animation effect for this process.
2. knowledge Point: The layoutanimationcontroller class is used to add animation effects to the sub-view. The layoutanimationcontroller must emphasize that different animation effects cannot be specified for each sub-view, however, the animation effect time can be displayed for each subview. 3. Example: The following shows how to add an animation effect to the subview of listview by combining the Alpha animation and the translate animation ..
There are two ways to use layoutanimationcontriller: one is to use it directly in the code or configure it in the XML text room. The following example will be used in the Code:
1 public class MainActivity extends Activity { 2 private ListView mListView; 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 mListView = (ListView) findViewById(R.id.listView); 8 mListView.setAdapter(new ArrayAdapter<String>(this, 9 android.R.layout.simple_list_item_1, Countries.COUNTRIES));10 AnimationSet set = new AnimationSet(true);11 Animation alpha = new AlphaAnimation(0.0f, 1.0f);12 alpha.setDuration(2000);13 Animation translate = new TranslateAnimation(14 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,15 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,16 Animation.RELATIVE_TO_SELF, 0.0f);17 translate.setDuration(1000);18 set.addAnimation(alpha);19 set.addAnimation(translate);20 LayoutAnimationController controller = new LayoutAnimationController(21 set);22 mListView.setLayoutAnimation(controller);23 }24 }
activity_main.xml
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context=".MainActivity" > 7 8 <ListView 9 android:id="@+id/listView"10 android:layout_width="match_parent"11 android:layout_height="match_parent" >12 </ListView>13 14 </LinearLayout>
Hacksix adds pleasing animation effects to the viewgroup subview