ANDROID_MARS學習筆記_S02_011_ANIMATION_LayoutAnimationController

來源:互聯網
上載者:User

標籤:

一、簡介

 

二、代碼
1.xml
(1)activity_main.xml

 1 <ListView 2         android:id="@id/android:list" 3         android:layout_width="wrap_content" 4         android:layout_height="wrap_content" 5         android:scrollbars="vertical"  6         /> 7         <!-- android:layoutAnimation="@anim/list_anim_layout" --> 8  9        <Button10         android:id="@+id/buttonId"11         android:layout_width="fill_parent"12         android:layout_height="wrap_content"13         android:text="測試"14         />

 

(2)item.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="fill_parent" android:layout_height="fill_parent" 4     android:orientation="horizontal" android:paddingLeft="10dip" 5     android:paddingRight="10dip" android:paddingTop="1dip" 6     android:paddingBottom="1dip"> 7      8     <TextView android:id="@+id/user_name" android:layout_width="180dip" 9         android:layout_height="30dip" android:textSize="5pt"10         android:singleLine="true"/>11     <TextView android:id="@+id/usr_gender" android:layout_width="fill_parent"12         android:layout_height="fill_parent" android:textSize="5pt" 13         android:singleLine="true"/>14 </LinearLayout>

(3)res\anim\list_anim.xml

1 <?xml version="1.0" encoding="utf-8"?>2 <set xmlns:android="http://schemas.android.com/apk/res/android"3     android:interpolator="@android:anim/accelerate_interpolator"4     android:shareInterpolator="true">5     6     <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />7 </set>

 

(3)res\anim\list_anim_layout.xml

1 <?xml version="1.0" encoding="utf-8"?>2 <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"3     android:delay="2"4     android:animationOrder="normal" 5     android:animation="@anim/list_anim" />

 

2.java
(1)MainActivity.java

 1 package com.layoutanimationcontroller; 2  3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6  7 import android.app.ListActivity; 8 import android.os.Bundle; 9 import android.view.View;10 import android.view.View.OnClickListener;11 import android.view.animation.Animation;12 import android.view.animation.AnimationUtils;13 import android.view.animation.LayoutAnimationController;14 import android.widget.Button;15 import android.widget.ListAdapter;16 import android.widget.ListView;17 import android.widget.SimpleAdapter;18 19 public class MainActivity extends ListActivity {20     21     private Button button = null;22     private ListView listView = null;23     24     @Override25     protected void onCreate(Bundle savedInstanceState) {26         super.onCreate(savedInstanceState);27         setContentView(R.layout.activity_main);28         listView = getListView();29         button = (Button)findViewById(R.id.buttonId);30         button.setOnClickListener(new ButtonListener());31     }32     33     class ButtonListener implements OnClickListener {34         @Override35         public void onClick(View v) {36             listView.setAdapter(buidListAdapter());37             Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.list_anim);38             LayoutAnimationController lac = new LayoutAnimationController(animation);39             lac.setOrder(LayoutAnimationController.ORDER_NORMAL);40             lac.setDelay(0.5f);41             listView.setLayoutAnimation(lac);42         }43     }44 45     private ListAdapter buidListAdapter() {46         List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();47         HashMap<String, String> m1 = new HashMap<String,String>();48         m1.put("user_name", "張三");49         m1.put("user_gender", "女");50 51         HashMap<String, String> m2 = new HashMap<String, String>();52         m2.put("user_name", "李四");53         m2.put("user_gender", "女");54 55         HashMap<String, String> m3 = new HashMap<String, String>();56         m3.put("user_name", "王五");57         m3.put("user_gender", "男");58         59         list.add(m1);60         list.add(m2);61         list.add(m3);62         63         SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.item, 64                 new String[] {"user_name", "user_gender"}, 65                 new int[] {R.id.user_name, R.id.usr_gender});66         return simpleAdapter;67     }68 }

 

 

 

ANDROID_MARS學習筆記_S02_011_ANIMATION_LayoutAnimationController

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.