fragment切换页面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".activity.Home_page_Activity">
<FrameLayout
android:id="@+id/main_frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<RadioGroup
android:padding="@dimen/dp_10"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="@drawable/rectangle"
android:layout_height="@dimen/dp_120">
<RadioButton
android:id="@+id/rb_show"
android:checked="true"
style="@style/main_bottom_btn_style"
android:drawableTop="@drawable/home_page_selector1"/>
<RadioButton
android:id="@+id/rb_circle"
style="@style/main_bottom_btn_style"
android:drawableTop="@drawable/home_page_selector2"/>
<RadioButton
android:id="@+id/rb_shopcar"
style="@style/main_bottom_btn_style"
android:layout_marginTop="0dp"
android:drawableTop="@drawable/shopping_two"
android:layout_marginLeft="-3dp" />
<RadioButton
android:id="@+id/rb_list"
style="@style/main_bottom_btn_style"
android:drawableTop="@drawable/home_page_selector3"/>
<RadioButton
android:id="@+id/rb_mine"
style="@style/main_bottom_btn_style"
android:drawableTop="@drawable/home_page_selector4"/>
</RadioGroup>
</RelativeLayout>
切换的代码
@Override
protected void initView() {
one = new frag_01();
two = new frag_02();
three = new frag_03();
four = new frag_04();
five = new frag_05();
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.main_frameLayout, one);
transaction.add(R.id.main_frameLayout, two);
transaction.add(R.id.main_frameLayout, three);
transaction.add(R.id.main_frameLayout, four);
transaction.add(R.id.main_frameLayout, five);
//进行显隐切换
transaction.show(one).hide(two).hide(three).hide(four).hide(five).commit();
FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
transaction1.show(one).hide(two).hide(three).hide(four).hide(five).commit();
}
点击事件的切换
@OnClick(R.id.rb_show)
public void show() {
FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
transaction1.show(one).hide(two).hide(three).hide(four).hide(five).commit();
}
@OnClick(R.id.rb_circle)
public void circle() {
FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction();
transaction2.show(two).hide(one).hide(three).hide(four).hide(five).commit();
}
@OnClick(R.id.rb_shopcar)
public void shopcar() {
FragmentTransaction transaction3 = getSupportFragmentManager().beginTransaction();
transaction3.show(three).hide(two).hide(one).hide(four).hide(five).commit();
}
@OnClick(R.id.rb_list)
public void list() {
FragmentTransaction transaction4 = getSupportFragmentManager().beginTransaction();
transaction4.show(four).hide(two).hide(one).hide(three).hide(five).commit();
}
@OnClick(R.id.rb_mine)
public void mine() {
FragmentTransaction transaction5 = getSupportFragmentManager().beginTransaction();
transaction5.show(five).hide(two).hide(one).hide(three).hide(four).commit();
}