布局动画 属性初始 android:animateLayoutChanges

容器控件  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;
    }
}


你可能感兴趣的:(view,布局)