android Animations 动画效果(四)
2014-03-11 18:19
337 查看
1.LayoutAnimationController的使用方法
什么是LayoutAnimationController
1.LayoutAnimationController用于为一个layout里面的控件,或者是一个
ViewGroup里面的控件设置动画效果
2.每一个控件都有相同的动画效果
3.这些控件的动画效果在不同的时间显示出来
4.LayoutAnimationController可以在xml文件中设置,也可以在代码中设置
2.ListView与Animations结合使用
在代码中使用LayoutAnimationController
1.创建一个Animation对象:
可以通过装载xml文件,或者直接使用Animation的构造函数创建Animation对象
2使用如下代码创建LayoutAnimationController对象:
LayoutAnimationController lac = new LayoutAnimationController
(animation);
3.设置控件显示顺序:
lac.serOrder(LayoutAnimationController.ORDER_NORMAL)
4.为ListView设置LayoutAnimationController属性:
listView.setLayoutAnimation(lac);
MainActivity.java
package com.yx.animations04;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.yx.animations04.R;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends ListActivity {
private Button button=null;
private ListView listView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonId);
button.setOnClickListener(new buttonListener());
listView = getListView();
}
private ListAdapter buildListAdapter(){
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> m1 = new HashMap<String, String>();
m1.put("name", "张三");
m1.put("gender","女");
HashMap<String,String> m2 = new HashMap<String, String>();
m2.put("name", "李四");
m2.put("gender","女");
HashMap<String,String> m3 = new HashMap<String, String>();
m3.put("name", "王五");
m3.put("gender","男");
list.add(m1);
list.add(m2);
list.add(m3);
SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list,
R.layout.item, new String[]{"name","gender"}, new int[]{R.id.name,R.id.gender});
return simpleAdapter;
}
private class buttonListener implements OnClickListener{
@Override
public void onClick(View v) {
listView.setAdapter(buildListAdapter());
//在代码中实现,这里不需要list_anim_layout.xml文件
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.list_anim);
LayoutAnimationController lac = new LayoutAnimationController(animation);
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(lac);
}
}
}
list_anim_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animationOrder="normal"
android:animation="@anim/list_anim"
>
</layoutAnimation>
list_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"></alpha>
</set>
activity_main.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=".MainActivity" >
<!-- 使用配置文件
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layoutAnimation="@anim/list_anim_layout"
></ListView>
-->
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
></ListView>
<Button
android:id="@+id/buttonId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="测试动画效果"
/>
</LinearLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
什么是LayoutAnimationController
1.LayoutAnimationController用于为一个layout里面的控件,或者是一个
ViewGroup里面的控件设置动画效果
2.每一个控件都有相同的动画效果
3.这些控件的动画效果在不同的时间显示出来
4.LayoutAnimationController可以在xml文件中设置,也可以在代码中设置
2.ListView与Animations结合使用
在代码中使用LayoutAnimationController
1.创建一个Animation对象:
可以通过装载xml文件,或者直接使用Animation的构造函数创建Animation对象
2使用如下代码创建LayoutAnimationController对象:
LayoutAnimationController lac = new LayoutAnimationController
(animation);
3.设置控件显示顺序:
lac.serOrder(LayoutAnimationController.ORDER_NORMAL)
4.为ListView设置LayoutAnimationController属性:
listView.setLayoutAnimation(lac);
MainActivity.java
package com.yx.animations04;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.yx.animations04.R;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends ListActivity {
private Button button=null;
private ListView listView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonId);
button.setOnClickListener(new buttonListener());
listView = getListView();
}
private ListAdapter buildListAdapter(){
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> m1 = new HashMap<String, String>();
m1.put("name", "张三");
m1.put("gender","女");
HashMap<String,String> m2 = new HashMap<String, String>();
m2.put("name", "李四");
m2.put("gender","女");
HashMap<String,String> m3 = new HashMap<String, String>();
m3.put("name", "王五");
m3.put("gender","男");
list.add(m1);
list.add(m2);
list.add(m3);
SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list,
R.layout.item, new String[]{"name","gender"}, new int[]{R.id.name,R.id.gender});
return simpleAdapter;
}
private class buttonListener implements OnClickListener{
@Override
public void onClick(View v) {
listView.setAdapter(buildListAdapter());
//在代码中实现,这里不需要list_anim_layout.xml文件
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.list_anim);
LayoutAnimationController lac = new LayoutAnimationController(animation);
lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(lac);
}
}
}
list_anim_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animationOrder="normal"
android:animation="@anim/list_anim"
>
</layoutAnimation>
list_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"></alpha>
</set>
activity_main.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=".MainActivity" >
<!-- 使用配置文件
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layoutAnimation="@anim/list_anim_layout"
></ListView>
-->
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
></ListView>
<Button
android:id="@+id/buttonId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="测试动画效果"
/>
</LinearLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
相关文章推荐
- android动画效果之Animations(代码实现动画)
- Android 类似小红书标签效果(补间动画)
- [置顶] Android轻松搞定Dialog提示动画效果
- android 一个有漂亮动画效果的Dialog
- 【小超_Android】android上开源的酷炫的交互动画和视觉效果:Interactive-animation
- 【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- android可拖动的购物车效果(含点击放入购物车动画代码)
- Android2.0版本以下Activity切换动画效果
- Android动画效果translate、scale、alpha、rotate的 xml文件写法
- Android动画效果translate、scale、alpha、rotate详解
- Android利用ViewFlipper实现屏幕切换动画效果
- Android 中ViewPager 实现动画效果切换
- 一个比较有趣的 Android 动画效果
- Android中用ViewPager实现多页面滑动切换及动画效果的实例
- android tween 动画效果
- Android实现游戏中的渐隐和渐现动画效果
- 【Android UI设计与开发】第03期:引导界面(三)仿微信引导界面以及动画效果
- Android 仿余额宝数字动画效果
- Android动画效果 Android Animation