xml:
<android.support.v4.widget.DrawerLayout android:id="@+id/mydrawer" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/frame" ></FrameLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/rel_navigate" android:layout_alignParentBottom="true"> <RadioButton android:id="@+id/but1" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="首页" android:button="@null" android:gravity="center"/> <RadioButton android:id="@+id/but2" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="视频" android:button="@null" android:gravity="center"/> <RadioButton android:id="@+id/but3" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="我的" android:button="@null" android:gravity="center"/> </RadioGroup> </RelativeLayout> <RelativeLayout android:layout_width="260dp" android:layout_height="match_parent" android:id="@+id/rel_menu" android:layout_gravity="start" android:background="#550000ff"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_title" android:background="@mipmap/ic_launcher"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="sssssss" android:layout_below="@+id/img_title"/> </RelativeLayout> </android.support.v4.widget.DrawerLayout>
Activity:
public class MainActivity extends AppCompatActivity { private RadioButton b1; private RadioButton b2; private RadioButton b3; private Fragment1 fragment1; private Fragment2 fragment2; private Fragment3 fragment3; private DrawerLayout drawelauout; private ImageView imgTitle; private RelativeLayout relMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawelauout = (DrawerLayout) findViewById(R.id.mydrawer); imgTitle = (ImageView) findViewById(R.id.img_title); relMenu = (RelativeLayout) findViewById(R.id.rel_menu); b1 = (RadioButton) findViewById(R.id.but1); b2 = (RadioButton) findViewById(R.id.but2); b3 = (RadioButton) findViewById(R.id.but3); fragment1 = new Fragment1(); fragment2 = new Fragment2(); fragment3 = new Fragment3(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment1).commit(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment2).commit(); getSupportFragmentManager().beginTransaction().add(R.id.frame,fragment3).commit(); hide(); getSupportFragmentManager().beginTransaction().show(fragment1).commit(); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment1).commit(); } }); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment2).commit(); } }); b3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hide(); getSupportFragmentManager().beginTransaction().show(fragment3).commit(); } }); initdata(); } private void initdata() { imgTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //关闭,侧滑菜单 drawelauout.closeDrawer(relMenu); } }); } private void hide() { getSupportFragmentManager().beginTransaction().hide(fragment1).commit(); getSupportFragmentManager().beginTransaction().hide(fragment2).commit(); getSupportFragmentManager().beginTransaction().hide(fragment3).commit(); } }