在xml中使用LayoutAnimationController
来源:互联网 发布:软件测试过程管理 编辑:程序博客网 时间:2024/06/10 04:24
什么是LayoutAnimationController?
答:它是用于一个布局或者ViewGroup的动画控制器,它能够让每个子View在不同的时间点分别执行相同的动画。
案例:
点击按钮前
【中间有动画效果】
点击按钮后
步骤如下:
1.现在res/anim文件夹下创一个list_anim_layout.xml,该文件的作用是【为整个layout设置效果】
<?xml version="1.0" encoding="utf-8"?><layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:animationOrder="normal" android:delay="0.5" android:animation="@anim/list_anim"></layoutAnimation><!-- 专门为整个layout设置效果 -->
2.在res/anim文件夹下创建一个list_anim.xml,该文件的作用是【设置单个控件的效果】
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="2000" android:fromAlpha="0.0" android:toAlpha="1.0" /></set>
3.mainActivity.xml,在这个文件中一定别忘了【android:layoutAnimation="@anim/list_anim_layout"】
<LinearLayout 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" android:orientation="vertical" tools:context="${relativePackage}.${activityClass}" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="LayoutAnimationController " /> <ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:layoutAnimation="@anim/list_anim_layout" /> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试"/></LinearLayout>
4.item.xml
<LinearLayout 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" android:orientation="vertical" tools:context="${relativePackage}.${activityClass}" > <TextView android:id="@+id/userName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/userAge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
5.MainActivity.java
package com.fzq.layoutanimation;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.SimpleAdapter;public class MainActivity extends Activity {private Button buttonTest;private ListView listView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);buttonTest=(Button)findViewById(R.id.button);listView=(ListView)findViewById(R.id.listView);buttonTest.setOnClickListener(new ButtonListener());}private ListAdapter buildListAdapter(){List<HashMap<String, String>> list=new ArrayList<HashMap<String,String>>();HashMap<String, String> m1=new HashMap<String, String>();m1.put("userName", "秋词");m1.put("userAge", "17");HashMap<String, String> m2=new HashMap<String, String>();m2.put("userName", "瀚声");m2.put("userAge", "19");HashMap<String, String> m3=new HashMap<String, String>();m3.put("userName", "履善");m3.put("userAge", "18");list.add(m1);list.add(m2);list.add(m3);SimpleAdapter simpleAdapter=new SimpleAdapter(this, list, R.layout.item, new String[] {"userName","userAge"}, new int[]{R.id.userName,R.id.userAge});return simpleAdapter;}class ButtonListener implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stublistView.setAdapter(buildListAdapter());}}}
阅读全文
0 0
- 在xml中使用LayoutAnimationController
- 在代码中使用LayoutAnimationController
- 使用LayoutAnimationController
- LayoutAnimationController的初步使用
- LayoutAnimationController
- LayoutAnimationController
- LayoutAnimationController
- LayoutAnimationController
- LayoutAnimationController
- LayoutAnimationController
- 在gwt中使用XML
- 在unity3D中使用xml
- 在BCB6中使用XML
- Fragment在xml中使用
- XML在Unity中使用
- 【XML】XML在项目中使用
- 使用LayoutAnimationController实现ListView动画效果
- Databinding使用在XML中使用&&
- 数据分析学习
- 嵌入式linux 内核启动时动态加载驱动模块的方法
- linux中建立新的进程-fork、vfork、clone解析
- 面试题-前序中序序列重建二叉树
- C# 面向对象(Mp3实例优化 效果图)
- 在xml中使用LayoutAnimationController
- C语言入门
- LintCode python 小白-简单题-2 尾部的0
- 冒泡排序
- TCP 连接断连问题剖析 from IBM developerWorks
- note_cloud--创建笔记本
- sql server总结二
- 中文输入法中的全角和半角的区别
- python进阶