Android Animation 为布局添加动画效果
来源:互联网 发布:icloud怎么用恢复数据 编辑:程序博客网 时间:2024/05/20 20:57
该文章的目的就是为布局文件添加简单的动画效果:
实现效果图:
源代码:
fragment_main:
<?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="vertical" > <Button android:id="@+id/Button05" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button04" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button03" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button02" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button01" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /></LinearLayout>
MainActivity:
package com.animationdemo;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (savedInstanceState == null) {/** * 在Activity中动态的添加一个Fragment */getFragmentManager().beginTransaction().add(android.R.id.content, new PlaceholderFragment()).commit();}}}
PlaceholderFragment:
package com.animationdemo;import android.app.Fragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.view.animation.LayoutAnimationController;import android.view.animation.ScaleAnimation;import android.widget.LinearLayout;public class PlaceholderFragment extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {//获取该Fragment的布局文件LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);//设置动画的形式为缩放动画ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1);sa.setDuration(3000);//使用动画控制器,控制每个动画的显示时间(0.2f表示第一个按钮动画出现其整个的20%后,第二个按钮开始出现)。LayoutAnimationController lac = new LayoutAnimationController(sa, 0.2f);rootView.setLayoutAnimation(lac);return rootView;}}
源代码下载:
点击下载源码
0 0
- Android Animation 为布局添加动画效果
- AndroidUI 布局动画-为列表添加布局动画效果
- Android 动画效果 --Animation
- Android 动画效果 --Animation
- Android 动画效果 --Animation
- Android Animation动画效果
- android Animation 动画效果
- android Animation 动画效果
- Android 动画效果animation
- Android动画(Animation)效果
- android Animation动画效果
- Android - Animation动画效果
- Android:Animation动画效果
- android动画效果Animation
- 动画效果Animation-android
- android-Animation动画效果
- Android动画---Animation动画效果
- Android 动画效果 --Animation 动画
- UP智能家居系统之节点cc2530源码分析(1)
- 安卓图表引擎AChartEngine(四) - 源码示例 嵌入Acitivity中的折线图
- telnet 简单客户端学习
- OCP-1Z0-051 第116题 GROUP BY,HAVING子句应用
- java synchronized详解
- Android Animation 为布局添加动画效果
- Linux Shell 常用指令示例
- Foreach与迭代器
- Apple LLVM compiler 3.0 error file".h" has been modified.....
- HDOJ1176 免费馅饼 【DP】+【经典数塔】
- C#后台跨域访问,需要添加被访问的IP地址和域名
- scrapy - 2. 命令行工具
- Java之泛型编程
- mac系统文件共享