侧滑菜单

package com.example.myapplication.activity;

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

import com.example.myapplication.Base.BaseActivity;
import com.example.myapplication.Base.ui.nac.NocfourFragment;
import com.example.myapplication.Base.ui.nac.NoconeFragment;
import com.example.myapplication.Base.ui.nac.NocthreeFragment;
import com.example.myapplication.Base.ui.nac.NoctwoFragment;
import com.example.myapplication.R;

public class MainActivity extends BaseActivity {

    private DrawerLayout dl;
    private ImageView image_01;
    private ImageView image_02;
    private FrameLayout fragment;
    private RadioGroup radio_group;


    @Override
    protected void initData() {

        radio_group.check(R.id.noc_one);
    }

    @Override
    protected void setOnClickLisener() {

    }

    @Override
    protected void findView() {
        dl = findViewById(R.id.dl);
        image_01 = findViewById(R.id.image_show);
        image_02 = findViewById(R.id.imager_cehua);
        fragment = findViewById(R.id.frament);
        radio_group = findViewById(R.id.radio_group);

        image_01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.image_show:
                        if(dl.isDrawerOpen(Gravity.START)){
                            dl.closeDrawer(Gravity.START);
                        }else{
                            dl.openDrawer(Gravity.START);
                        }
                        break;

                }
            }
        });

        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                switch (checkedId){

                    case R.id.rb_1:
                         changpager(new NoconeFragment());
                        break;
                    case R.id.rb_2:
                        changpager(new NoctwoFragment());
                        break;
                    case R.id.rb_3:
                        changpager(new NocthreeFragment());
                        break;
                    case R.id.rb_4:
                        changpager(new NocfourFragment());
                        break;

                }
            }

            private void changpager(Fragment fragment) {
               getSupportFragmentManager().beginTransaction().replace(R.id.frament,fragment).commit();

            }
        });


    }

    @Override
    protected int initLayout() {

        return R.layout.activity_main;
    }

    @Override
    protected void setFullScreen() {

    }
}

 

 

 

xml代码

 

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/dl"
    tools:context=".activity.MainActivity"
    >
    <!--这是主页面-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_gravity="left"
            android:background="@color/colorPrimary">

            <ImageView
                android:id="@+id/image_show"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"


                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="菜单"
                />

        </LinearLayout>
        <FrameLayout
            android:id="@+id/frament"
            android:layout_weight="9"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="left"

            ></FrameLayout>
        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rb_1"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_weight="1"
                android:button="@null"
                android:checked="true"
                android:gravity="center"
                android:background="@drawable/noc_selector"
                android:text="头条"

                />

            <RadioButton
                android:id="@+id/rb_2"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:background="@drawable/noc_selector"
                android:text="福利"

                />

            <RadioButton
                android:id="@+id/rb_3"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:background="@drawable/noc_selector"
                android:text="任务"

                />

            <RadioButton
                android:id="@+id/rb_4"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:background="@drawable/noc_selector"
                android:text="我的" />
        </RadioGroup>

    </LinearLayout>

    <!--这是侧滑-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imager_cehua"
         />

    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值