容器控件 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. 三、安卓UI学习(1)
  2. android用户界面之按钮(Button)教程实例汇
  3. 关于Android(安卓)Studio3.2新建项目Android(安卓)resource link
  4. 在Fragment中设置控件点击方法,执行失败。
  5. Android(安卓)给 app默认权限(不弹窗申请权限)
  6. TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
  7. android 拨打紧急号码,通话时开启免提功能实现
  8. Android常用控件
  9. android用户界面-组件Widget-画廊视图Gallery

随机推荐

  1. Android(安卓)API等级、Android版本、发
  2. PULL解析XML
  3. Android(安卓)应用Crash 后自动重启
  4. Android文件列表RecyclerView中点击视频
  5. Android禁止下拉状态栏
  6. Android(安卓)之应用程序重启
  7. Android(安卓)9.0 P 状态栏下移的实现
  8. Android(安卓)复习笔记之图解Intent和Int
  9. AnimatedStateListDrawable介绍
  10. PULL解析XML