容器控件 android默认没有开启子控件变化的动画,也就是说animateLayoutChanges=false,animateLayoutChanges 属性 强调 必须api>=11 但是我测试了 在API=8上面没有报错,只是没有效果而已android:animateLayoutChanges="true" 表示开启系统的布局动画
实例:xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:animateLayoutChanges="true"    android:layout_height="match_parent">    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="add"        android:id="@+id/bt_add" /></LinearLayout>


代码:
package com.example.xuan.layoutAnimation;import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.LinearLayout;import java.util.Random;public class PlaceHolderFragment2 extends Fragment {    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {        final LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.fragment_main2, container, false);        rootView.findViewById(R.id.bt_add).setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                Button button = new Button(getActivity());                button.setText("" + new Random().nextInt(100));                rootView.addView(button);                button.setOnClickListener(new View.OnClickListener() {                    @Override                    public void onClick(View view) {                        rootView.removeView(view);                    }                });            }        });        return rootView;    }}


更多相关文章

  1. Android 在代码中同时给控件设置圆角和背景色
  2. Android动画开发——Animation动画效果
  3. Android 进阶——Material Design新控件之AppBarLayout+Toolbar+
  4. android三种动画
  5. Android 中替换开机动画(附动画包)
  6. Android属性动画之XML定义方式
  7. 【Android 开发】:Android中EditText控件的几种使用方法

随机推荐

  1. Android 自定义ProgressBar--进度自己设
  2. Android LruCache & DiskLruCache cooper
  3. android 序列化传值
  4. 【Android】使用代码动态创建布局
  5. Android UI控件详解-CheckBox(多选框)
  6. Android 本地图片多选
  7. Android 通过短链接,获取长连接
  8. Android 基于GeolocationAPI的基站定位
  9. Android – Video/Music 视频音乐播放
  10. android之简单的计算器样式界面