Animation使用方法(一)

本文详细介绍了如何在Android应用中利用LayoutAnimationController实现ListView中元素的平滑过渡显示效果,通过配置动画控制器和XML布局,使得列表项在页面加载时能够呈现出流畅的视觉体验。
这里要使用到LayoutAnimationController。这个类可以用在一个布局文件中的layout内,对该layout内部的控件进行控制,也可以用在Java代码中,实现同样的效果。
效果图:三个item逐个显现。
[img]
[img]http://dl.iteye.com/upload/attachment/617373/d5cde4e7-c948-3259-800e-92d221d33528.png[/img]
[/img]
工程结构图:
[img]
[img]http://dl.iteye.com/upload/attachment/617375/59744c26-4483-3396-82a4-0b820641f977.png[/img]
[/img]

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@id/android:list"
android:layoutAnimation="@anim/list_controller"
/>
</LinearLayout>


user.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/name"
android:layout_width="180dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:textColor="#fff"
android:textSize="10pt"
android:singleLine="true"
/>
<TextView
android:id="@+id/age"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:textColor="#fff"
android:gravity="right"
android:textSize="10pt"
/>
</LinearLayout>


/res/anim/alpha.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="0.0"
android:toAlpha="1.0"
android:duration="2000"
></alpha>
</set>

/res/anim/list_controller.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/alpha"
/>


AnimationDemo3Activity
package cxt.demo;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

public class AnimationDemo3Activity extends ListActivity {
private ArrayList<HashMap<String,Object>> list = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

list = new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> m1 = new HashMap<String, Object>();
HashMap<String,Object> m2 = new HashMap<String, Object>();
HashMap<String,Object> m3 = new HashMap<String, Object>();
m1.put("image", R.drawable.z11);
m1.put("name", "Jack");
m1.put("age","63");
m2.put("image", R.drawable.z22);
m2.put("name", "Bob");
m2.put("age","15");
m3.put("image", R.drawable.z33);
m3.put("name", "Theron");
m3.put("age","25");
list.add(m1);
list.add(m2);
list.add(m3);
SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.user, new String[]{"image","name","age"}, new int[]{R.id.image,R.id.name,R.id.age});
setListAdapter(adapter);
}


}


本文转自:http://theron.blog.51cto.com/2383825/656690
只可用做学习。
### ### -webkit-animation 属性的使用方法和语法说明 -webkit-animation个复合属性,用于在支持 WebKit 内核的浏览器(如 Safari 和旧版 Chrome)中定义动画效果。它结合了多个单独的动画属性,如 animation-name、animation-duration 等[^3]。 #### 语法 ```css -webkit-animation: name duration timing-function delay iteration-count direction fill-mode play-state; ``` - **name**:指定关键帧动画的名称。 - **duration**:定义动画完成个周期所需的时间,单位为秒 (s) 或毫秒 (ms)。 - **timing-function**:定义动画的速度曲线,默认值为 `ease`。 - **delay**:定义动画开始前的延迟时间。 - **iteration-count**:定义动画播放的次数,可以是具体的数字或 `infinite` 表示无限循环。 - **direction**:定义动画是否交替反向播放,可选值为 `normal` 或 `alternate`。 - **fill-mode**:定义动画外的关键帧样式如何应用于元素。 - **play-state**:定义动画是否正在运行或已暂停,可选值为 `running` 或 `paused`。 #### 示例代码 以下是个完整的示例,展示如何使用 `-webkit-animation` 属性: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>-webkit-animation 示例</title> <style> /* 定义关键帧 */ @-webkit-keyframes mymove { from { transform: translateX(0); } to { transform: translateX(200px); } } /* 应用动画 */ #box { width: 50px; height: 50px; background-color: red; -webkit-animation: mymove 2s ease-in-out 1s infinite alternate running; } </style> </head> <body> <div id="box"></div> </body> </html> ``` 在上述代码中: - 使用 `@-webkit-keyframes` 定义了个名为 `mymove` 的动画,使元素从左到右移动 200 像素。 - `-webkit-animation` 属性将动画应用到 `#box` 元素上,设置了动画的名称 (`mymove`)、持续时间 (`2s`)、速度曲线 (`ease-in-out`)、延迟 (`1s`)、播放次数 (`infinite`)、方向 (`alternate`) 和播放状态 (`running`)。 #### 注意事项 - `-webkit-animation` 是针对 WebKit 内核浏览器的前缀属性,在现代浏览器中通常可以直接使用 `animation` 属性[^1]。 - 如果需要兼容其他浏览器,可以同时定义无前缀版本和其他前缀版本的动画属性[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值