Android5.0 in the so-called animation can be a unique, in the design specifications in a large number of display of the ListView animation, in fact, is a purpose: the items animated display. This looks very flashy effect, in fact, the implementation is quite simple, I will be the following to use animation simple implementation.
I. Creating an animated file in an XML file
This step I recommend writing animations in XML, the advantage is that your entire application can invoke this effect, guaranteeing style and reducing redundancy. My usual attitude to animations is: Simple animations with XML files, complex animations with objectanimation.
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/decelerate_interpolator"Android:shareinterpolator= "true"> <Translateandroid:duration= "1300"Android:fromxdelta= "0%"Android:fromydelta= "100%"Android:toxdelta= "0%"Android:toydelta= "0%" /> <Alphaandroid:duration= "1300"Android:fromalpha= "0"Android:toalpha= "1.0" /></Set>
Here you can see I wrote two animations, one from scratch, and one from bottom to top. In order to facilitate the demonstration, I have made the animation time more long.
Second, configure in the code
PackageCom.example.googleplusliststyle;Importjava.util.Arrays;Importjava.util.List;ImportJava.util.Locale;Importandroid.app.Activity;ImportAndroid.os.Bundle;Importandroid.view.animation.Animation;Importandroid.view.animation.AnimationUtils;ImportAndroid.view.animation.LayoutAnimationController;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.ListView; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); FinalListView ListView =(ListView) Findviewbyid (R.id.listview); List<String> data = Arrays.aslist (Locale.getisocountries ());//Get demo list dataarrayadapter<string> adapter =NewArrayadapter<string> ( This, R.layout.item, R.id.mytextview,data); Listview.setadapter (adapter); Animation Animation= Animationutils.loadanimation ( This, R.anim.from_bottom_to_top); FinalLayoutanimationcontroller Controller =NewLayoutanimationcontroller (animation, 0); Listview.setlayoutanimation (Controller); Listview.setdivider (NULL); //listview.startanimation (animation); }}
The code is also very simple, load the listview in the layout file first, write the item, then configure the animation by Layoutanimationcontroller, and finally let the ListView load the animation.
Layoutanimationcontroller constructor We mainly look at the second parameter, if set 0, all item is animated at the same time, if it is 1, it will let the item one by one display animation.
Activity_main.xml
<Relativelayoutxmlns: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"Tools:context=". Mainactivity " > <ListViewAndroid:id= "@+id/listview"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true" > </ListView></Relativelayout>
Item.xml
<Relativelayoutxmlns: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"> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world"Android:id= "@+id/mytextview"Android:layout_margin= "16DP"android:textsize= "18SP"/> <ViewAndroid:layout_width= "Match_parent"Android:layout_height= "2DP"Android:layout_below= "@id/mytextview"Android:background= "#888888"/></Relativelayout>
Third, another way: Set the animation in the layout file
If we want to use animation in XML, we need to create an animation file
Anim_layout.xml
<? XML version= "1.0" encoding= "Utf-8" ?> < xmlns:android= "http://schemas.android.com/apk/res/android" android: Animation= "@anim/from_bottom_to_top" android:animationorder= "normal" android:delay= "0"/>
The value of Android:animationorder here is normal:0 default; reverse:1 reverse; Random:2 random. is to sort the animations, I set the Noraml.
This file refers to an animation we wrote earlier, which is equivalent to the previous animation being layoutanimation wrapped.
Animating in the ListView
<ListViewAndroid:id= "@+id/listview"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"android:layoutanimation= "@anim/anim_layout"> </ListView>
The key is this layoutanimation property, set on the animation we just finished it on the line.
The effect is as follows:
SOURCE Download:http://download.csdn.net/detail/shark0017/8273763
Reference from:
http://blog.csdn.net/jdsjlzx/article/details/7652297
http://blog.csdn.net/jdsjlzx/article/details/7652452
http://blog.csdn.net/lixiaodaoaaa/article/details/8284246
Http://droidyue.com/blog/2014/07/26/apply-google-plus-list-style-on-android/
Simple implementation of Android5.0 listview effects