挤出点时间迅速把这篇博文完成。

---------------------------------------------------------------------------------------------------------


1. 在 Android3.0+ 平台下可以直接使用 LayoutTransition 类实现上图效果(笔者随手制作的gif,见谅见谅),实现代码:

package com.soxfmr.anim;import android.animation.LayoutTransition;import android.content.Context;import android.util.AttributeSet;import android.widget.RelativeLayout;public class Container extends RelativeLayout {public Container(Context context, AttributeSet attrs) {super(context, attrs);LayoutTransition transition = new LayoutTransition();this.setLayoutTransition(transition);}}

接下来直接调用 addView 添加子元素即可看到效果。

---------------------------------------------------------------------------------------------------------


2. 如果app支持到 Android2.1 平台,那么 LayoutTransition 就无法使用,通过 Animation 实现上图效果:

package com.soxfmr.anim;import android.content.Context;import android.util.AttributeSet;import android.view.animation.AlphaAnimation;import android.widget.RelativeLayout;import android.widget.TextView;public class Container extends RelativeLayout {private Context mContext;public Container(Context context, AttributeSet attrs) {super(context, attrs);mContext = context;}public void addview() {TextView item = new TextView(mContext);//set the animation effects to the itemAlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);alphaAnimation.setDuration(800);//add the item to parent view while starting animationitem.startAnimation(alphaAnimation);this.addView(item);}}

---------------------------------------------------------------------------------------------------------

3. 结合代码,以适应不同平台:

package com.soxfmr.anim;import android.animation.LayoutTransition;import android.content.Context;import android.os.Build;import android.util.AttributeSet;import android.view.View;import android.view.animation.AlphaAnimation;import android.widget.RelativeLayout;import android.widget.TextView;public class Container extends RelativeLayout {private Context mContext;private boolean bAnimMode = false;public boolean isbAnimMode() {return bAnimMode;}/** true is open the animation effects. */public void setbAnimMode(boolean bAnimMode) {this.bAnimMode = bAnimMode;}public Container(Context context, AttributeSet attrs) {super(context, attrs);mContext = context;//If the platform is Android3.0 upperif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {final LayoutTransition transition = new LayoutTransition();this.setLayoutTransition(transition);    }else {    setbAnimMode(true);    }}public void addview() {TextView item = new TextView(mContext);refreshView(item);this.addView(item);}public void refreshView(View item) {if( ismAnimMode() ) {//set the animation effects to the itemAlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);alphaAnimation.setDuration(800);//add the item to parent view while starting animationitem.startAnimation(alphaAnimation);}}}

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. python list.sort()根据多个关键字排序的方法实现
  3. Android实现下载文件功能的方法
  4. Android(安卓)5.x特性概览二
  5. android实践项目一实现简单的验证码和spinner下拉选项效果
  6. android 中使用TextView实现分段显示不同颜色的字符串
  7. APIDEMO PREFERENCE 学习 ACTIVTIY
  8. Hybrid(在Android中的实现)
  9. Android(安卓)中文 API (35) —— ImageSwitcher

随机推荐

  1. StagefrightPlayer&&AwesomePlayer 初步
  2. cvc-complex-type.2.4.d: 发现了以元素 '
  3. Laravel 创建可以传递参数 Console服务的
  4. laravel 根据不同组织加载不同视图的实现
  5. laravel 实现划分admin和home 模块分组
  6. laravel在中间件内生成参数并且传递到控
  7. laravel通过a标签从视图向控制器实现传值
  8. linux文本处理三剑客之awk
  9. 解决在laravel中leftjoin带条件查询没有
  10. 解决Laravel5.5下的toArray问题