码迷,mamicode.com
首页 > 其他好文 > 详细

动画布局管理器

时间:2015-07-23 17:35:20      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

package cativity.cyq.layoutanimation;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LayoutAnimationController;
import android.view.animation.ScaleAnimation;
import android.widget.LinearLayout;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().addToBackStack(null)
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);
            ScaleAnimation sAnimatio = new ScaleAnimation(0, 1, 0, 1);
            sAnimatio.setDuration(200);
            //使用布局动画管理器

            LayoutAnimationController layoutAniController = new LayoutAnimationController(sAnimatio, 0.9f);
            rootView.setLayoutAnimation(layoutAniController);

            rootView.findViewById(R.id.skipto).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getFragmentManager().beginTransaction().addToBackStack(null)
                            .replace(R.id.container, new MyFragment())
                            .commit();


                }
            });

            return rootView;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


}

 

动画布局管理器

标签:

原文地址:http://www.cnblogs.com/chenyangqi/p/4670913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!