您的位置:首页 > 移动开发 > Android开发

Android 组件动画

2016-07-12 15:54 567 查看

Android 组件动画

LayoutAnimationController可以控制一组控件按照规定显示。

1、资源文件anim_layout.xml

delay,动画间隔时间,子类动画时间间隔。
animationOrder,动画执行的循序(normal:顺序,random:随机,reverse:反向显示)。
animation,引用动画效果文件。

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="0.1"
android:animationOrder="normal"
android:animation="@anim/anim_right_to_left" />

2、资源文件anim_right_to_left.xml

控件从左往右出现。
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="1000" />

3、布局文件activity_controller_animation.xml

layoutAnimation,引用layoutAnimation资源文件。
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/anim_layout" />

4、Activity

在Activity中包含一个列表,列表内容依次从上往下,从右往左出现,每列动画持续1秒,列表之间相差0.1秒。
public class AnimationControllerActivity extends Activity {
private String[] month = new String[]{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_controller_animation);

ListView lv = (ListView) findViewById(R.id.listview);
lv.setAdapter(new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, month));
}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: