抽屉布局加上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;
}
}
});
}
}