Android development for ListView set layout animation effect

Source: Internet
Author: User

1. By adding Java code , the resource file is basically not modified

XML file, just add a ListView and do not paste the code of the XML file.

Java code:

1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7 8Scaleanimation sa=NewScaleanimation (0, 1, 0, 1);9Sa.setduration (1000);TenLayoutanimationcontroller lac=NewLayoutanimationcontroller (SA, 0.5f); One Lac.setorder (layoutanimationcontroller.order_reverse); A  -ListView lv=(ListView) Findviewbyid (r.id.lv); -Arrayadapter<string> adapter=NewArrayadapter<string> (Getapplicationcontext (), Android. R.layout.simple_list_item_1,Newstring[]{"Beijing", "Xian", "Shanghai", "Nanjing"}); the Lv.setadapter (adapter); - Lv.setlayoutanimation (LAC); -         } -}

2. Add animation effects through a resource file

To create a new Android XML fils, on the new page, Resource type selected for tween animation,root element is selected as Alpha. (You can also set multiple animation effects together)

Scale_anim.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 < Scalexmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:fromxscale= "0"4 Android:toxscale= "1"5 Android:fromyscale= "0"6 Android:toyscale= "1"7 android:duration= "+">8 </ Scale>

Create a new Android XML fils

Listview_anim.xml

 1  <?  xml version= "1.0" encoding= "Utf-8"  ?>  2   xmlns:android   3   Android:animation  = "@anim/scale_anim"  4   Android:delay  = "0.5"  5  </ layoutanimation  >  

In the Main-activity.xml file, set the properties of the ListView

1     <  android:id= "@+id/lv"2        android:layout_width= "Match_parent "3        android:layout_height=" Match_parent "4         Android:layoutanimation= "@anim/listview_anim"></listview> 

Android development for ListView set layout animation effect

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.