该文章的目的就是为布局文件添加简单的动画效果:

实现效果图:

Android Animation 为布局添加动画效果_第1张图片

源代码:Android Animation 为布局添加动画效果_第2张图片


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;}}

源代码下载:

点击下载源码



更多相关文章

  1. android 开发 RecyclerView 横排列列表布局
  2. 增加滚动布局
  3. 帧动画
  4. [置顶] 我的Android进阶之旅------>Android之动画之Frame Animat
  5. android 自定义属性实现 ImageView 透明度渐变效果
  6. 实现Android立体翻页效果的工具类!
  7. Android简单实现启动画面的方法
  8. android中简单的图片翻页效果
  9. android按Menu出现菜单的动画

随机推荐

  1. ANDROID 单元测试
  2. Android 抖动效果
  3. Android更新Ui的几种方法和见解
  4. launcher学习
  5. 【Android】常见布局xml参数详解
  6. [android]EditText的一些设置
  7. Android:官网ROM下载地址备份
  8. Android EditText 不自动获取焦点(不自动
  9. Android 签名验证
  10. Android 多媒体播放器