fragment 模型

来源:互联网 发布:印尼网络制式 编辑:程序博客网 时间:2024/06/05 19:35

/////////////////////////////////////布局//////////////////////////////////////

<RadioGroup    android:layout_width="match_parent"    android:layout_height="50dp"    android:id="@+id/group"    android:orientation="horizontal"    android:layout_alignParentBottom="true"    >    <RadioButton        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/button1"        android:layout_weight="1"        android:button="@null"        android:gravity="center"        android:text="首页"        />    <RadioButton        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/button2"        android:layout_weight="1"        android:button="@null"        android:gravity="center"        android:text="发现"        />    <RadioButton        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/button3"        android:layout_weight="1"        android:button="@null"        android:gravity="center"        android:text="下载"        />    <RadioButton        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/button4"        android:layout_weight="1"        android:button="@null"        android:gravity="center"        android:text="我的"        /></RadioGroup><FrameLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    android:id="@+id/frame"    android:layout_above="@+id/group"    ></FrameLayout>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////主函数

group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {    @Override    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {        switch (checkedId){            case R.id.button1:                getSupportFragmentManager().beginTransaction().replace(R.id.frame,new One()).commit();                break;            case R.id.button2:                getSupportFragmentManager().beginTransaction().replace(R.id.frame,new Two()).commit();                break;            case R.id.button3:                getSupportFragmentManager().beginTransaction().replace(R.id.frame,new Three()).commit();                break;            case R.id.button4:                getSupportFragmentManager().beginTransaction().replace(R.id.frame,new Four()).commit();                break;        }    }});