静态fragment页面

xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity">

    <android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/drawer">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <FrameLayout
                android:id="@+id/fragme"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </FrameLayout>
            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/mgroup"
                android:orientation="horizontal"
                android:gravity="center"
                android:layout_alignBottom="@+id/fragme">
                <RadioButton
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/button1"
                    android:text="button1"
                    android:layout_weight="1"/>
                <RadioButton
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/button2"
                    android:text="button1"
                    android:layout_weight="1"/>
                <RadioButton
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/button3"
                    android:text="button1"
                    android:layout_weight="1"/>
                <RadioButton
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/button4"
                    android:text="button1"
                    android:layout_weight="1"/>


            </RadioGroup>

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start">

        </RelativeLayout>
    </android.support.v4.widget.DrawerLayout>


</RelativeLayout>

JAVA代码实现

public class Main2Activity extends FragmentActivity {

    private FrameLayout frameLayout;
    private DrawerLayout drawerLayout;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private RadioGroup group;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        
        drawerLayout = findViewById(R.id.drawer);
        frameLayout = findViewById(R.id.fragme);
        group = findViewById(R.id.mgroup);
        
        fragmentManager = getSupportFragmentManager();
        
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fragme,new Frag01());
        transaction.add(R.id.fragme,new Frag02());
        transaction.replace(R.id.fragme,new Frag01());
        transaction.commit();
        
        group.check(group.getChildAt(0).getId());
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            private FragmentTransaction transaction;

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                transaction = fragmentManager.beginTransaction();

                switch (checkedId){
                    case R.id.button1:
                        transaction.replace(R.id.fragme,new Frag01());
                        break;
                    case R.id.button2:
                        transaction.replace(R.id.fragme,new Frag02());
                        break;
                    case R.id.button3:
                        transaction.replace(R.id.fragme,new Frag03());
                        break;
                    case R.id.button4:
                        transaction.replace(R.id.fragme,new Frag04());
                        break;
                }
                transaction.commit();
            }
        });
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值