抽屉布局加上RadioGroup+点击进行切换

抽屉布局加上RadioGroup
?xml version=”1.0” encoding=”utf-8”?>
android.support.v4.widget.DrawerLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:id=”@+id/drawer_layout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<RelativeLayout
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/fragment_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></FrameLayout>
    <RadioGroup
        android:layout_alignParentBottom="true"
        android:id="@+id/radio_group"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <RadioButton
            android:id="@+id/bt02"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:background="@drawable/radio_selector"
            android:checked="true"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="首页"
            android:layout_weight="1"/>

        <RadioButton
            android:id="@+id/bt03"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:background="@drawable/radio_selector"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="联系人"
            android:layout_weight="1"/>

        <RadioButton
            android:id="@+id/bt04"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:background="@drawable/radio_selector"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="视频"
            android:layout_weight="1"/>

        <RadioButton
            android:id="@+id/bt01"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:background="@drawable/radio_selector"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="我的"
            android:layout_weight="1"/>
    </RadioGroup>
</RelativeLayout>

<!-- 抽屉布局-->
<LinearLayout
    android:background="#ffffff"
    android:id="@+id/liner_drawer"
    android:layout_gravity="left"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:text="你好"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:text="未登录"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>

Activity

package com.example.day02_0927;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {

private DrawerLayout drawerlayout;
private RadioGroup radiogroup;
private LinearLayout linearLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    drawerlayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    radiogroup = (RadioGroup) findViewById(R.id.radio_group);
    linearLayout = (LinearLayout) findViewById(R.id.liner_drawer);

    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout,new FragmentNews()).commit();
    radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId){
                case R.id.bt01:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout,new FragmentNews()).commit();
                    break;
                case R.id.bt02:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout,new FragmentNews()).commit();
                    break;
                case R.id.bt03:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout,new FragmentNews()).commit();
                    break;
                case R.id.bt04:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout,new FragmentNews()).commit();
                    break;
            }
        }
    });
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值