Learn about Android settings ListView data Display animation effect (24)

Source: Internet
Author: User

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvagfpx3fpbmdfehvfa29uzw==/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center ">


Usually we want to achieve the ListView data display animation effect, can use Layoutanimationcontroller to animate the ListView, and through the ListView Setlayoutanimation method to set, Finally Startlayoutanimation, start the animation. Take a look at the following code:

public class Mainactivity extends Activity {private ListView lv_arrayadapter;private string[] str_name = new string[] {"J Ack "," Debb "," Robin "," Kikt "," Dog "," cat "," Elep "}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Initview (); SetData (); Loadanimation ();} private void Loadanimation () {/* * Creates a collection of animations */animationset set = new Animationset (false); Animation Animation; */* Create a rotation animation */animation = new Rotateanimation (+); animation.setduration (1000); Set.addanimation (animation); Layoutanimationcontroller controller = new Layoutanimationcontroller (set, 1); Controller.setinterpolator (This, Android. R.anim.accelerate_interpolator); controller.setanimation (set); Lv_arrayadapter.setlayoutanimation (Controller); LV _arrayadapter.startlayoutanimation ();} private void Initview () {lv_arrayadapter = (ListView) Findviewbyid (r.id.lv_arrayadapter);//Register Listener event Lv_ Arrayadapter.setonitemclicklistener (New OnitemclicKlistener () {@Overridepublic void Onitemclick (adapterview<?> parent, View view,int position, long ID) { Toast.maketext (Mainactivity.this, Str_name[position],toast.length_short). Show ();}}); private void SetData () {//create arrayadapterarrayadapter<string> Arrayadapter = new Arrayadapter<string> ( Mainactivity.this, Android. R.layout.simple_list_item_1,str_name);//Bind adapter Lv_arrayadapter.setadapter (Arrayadapter);}}


Activity_main.xml:

<relativelayout 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 "   >    <listview          android:id= "@+id/lv_arrayadapter"          android:layout_width= "Fill_parent          " android:layout_height= "Wrap_content" >      </ListView>  </RelativeLayout>



Reprint Please specify the Source:http://blog.csdn.net/hai_qing_xu_kong/article/details/44248637Emotional Control _

Learn about Android settings ListView data Display animation effect (24)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.