新的MainActivity

package cn.zhaoliang5156.toutiao1630a.ui.fragment.activity;


import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioGroup;


import cn.zhaoliang5156.toutiao1630a.R;
import cn.zhaoliang5156.toutiao1630a.base.BaseActivity;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavFourFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavOneFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavThreeFragment;
import cn.zhaoliang5156.toutiao1630a.ui.fragment.nav.NavTwoFragment;

/**
 * 程序首页面
 *
 * @author zhaoliang
 * @version 1.0
 * @create 2018/7/24
 */
public class MainActivity extends BaseActivity implements View.OnClickListener {


    private static final String TAG = MainActivity.class.getSimpleName();
    private ImageView ivHead;

    // 侧滑菜单
    private DrawerLayout drawerLayout;

    // 主内容区域
    private FrameLayout flContainer;
    // 底部导航
    private RadioGroup navRadioGroup;

    @Override
    protected void setOnClickLisener() {
        ivHead.setOnClickListener(this);
        drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
                Log.i(TAG, "===:" + slideOffset);
                //滑动过程中不断回调 slideOffset:0~1
                View content = drawerLayout.getChildAt(0);
                float scale = 1 - slideOffset;//1~0
                content.setTranslationX(drawerView.getMeasuredWidth() * (1 - scale));//0~width
            }

            @Override
            public void onDrawerOpened(@NonNull View drawerView) {

            }

            @Override
            public void onDrawerClosed(@NonNull View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

        navRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_nav_one:
                        changePager(new NavOneFragment());
                        break;
                    case R.id.rb_nav_two:
                        changePager(new NavTwoFragment());
                        break;
                    case R.id.rb_nav_three:
                        changePager(new NavThreeFragment());
                        break;
                    case R.id.rb_nav_four:
                        changePager(new NavFourFragment());
                        break;
                }
            }
        });
    }

    /**
     * 改变页面
     *
     * @param fragment
     */
    private void changePager(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fl_container, fragment).commit();
    }

    @Override
    protected void initData() {
        // 选中第一个页面
        navRadioGroup.check(R.id.rb_nav_one);
    }

    @Override
    protected void findView() {
        ivHead = findViewById(R.id.iv_head);
        drawerLayout = findViewById(R.id.draw_layout);
        flContainer = findViewById(R.id.fl_container);
        navRadioGroup = findViewById(R.id.rg_nav);
    }

    @Override
    protected void setFullScreen() {

    }

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            // 点击头像 展开侧滑
            case R.id.iv_head:
                if (drawerLayout.isDrawerOpen(Gravity.START)) {
                    drawerLayout.closeDrawer(Gravity.START);
                } else {
                    drawerLayout.openDrawer(Gravity.START);
                }
                break;
        }
    }
}

/闪屏activity

package cn.zhaoliang5156.toutiao1630a.ui.fragment.activity;

import android.content.Intent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

import cn.zhaoliang5156.toutiao1630a.R;
import cn.zhaoliang5156.toutiao1630a.base.BaseActivity;

/**
 * 闪屏页面
 *
 * @author zhaoliang
 * @version 1.0
 * @create 2018/7/24
 */
public class SplashActivity extends BaseActivity implements Animation.AnimationListener {

    // 渐变动画
    private AlphaAnimation alphaAnimation;
    // 跟布局
    private RelativeLayout rlSplash;

    @Override
    protected void setOnClickLisener() {

    }

    @Override
    protected void initData() {
        alphaAnimation = new AlphaAnimation(0, 1);
        alphaAnimation.setDuration(2000);
        alphaAnimation.setAnimationListener(this);

        rlSplash.startAnimation(alphaAnimation);
    }

    @Override
    protected void findView() {
        rlSplash = findViewById(R.id.rl_splash);
    }

    @Override
    protected void setFullScreen() {
        fullScreen();
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_splash;
    }

    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        toMain();
    }

    /**
     * 跳转到主界面
     */
    private void toMain() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值