FrameLayout + RadioGroup

<LinearLayout 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:orientation="vertical"
    android:layout_height="match_parent"
    tools:context="com.example.zhoukao1.MainActivity">

    <FrameLayout
        android:id="@+id/framelayout"
        android:layout_weight="9"
        android:layout_width="match_parent"
        android:layout_height="0dp"></FrameLayout>
    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:layout_height="0dp">
        <RadioButton
            android:id="@+id/rb1"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="新品"
            android:layout_height="match_parent" />
        <RadioButton
            android:id="@+id/rb2"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:button="@null"
            android:text="精选"
            android:layout_height="match_parent" />
        <RadioButton
            android:id="@+id/rb3"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:button="@null"
            android:text="分类"
            android:layout_height="match_parent" />
        <RadioButton
            android:id="@+id/rb4"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:button="@null"
            android:text="我的衣橱"
            android:layout_height="match_parent" />
        <RadioButton
            android:id="@+id/rb5"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:button="@null"
            android:text="个人中心"
            android:layout_height="match_parent" />
    </RadioGroup>
</LinearLayout>
public class MainActivity extends AppCompatActivity {

    @BindView(R.id.framelayout)
    FrameLayout framelayout;
    @BindView(R.id.rb1)
    RadioButton rb1;
    @BindView(R.id.rb2)
    RadioButton rb2;
    @BindView(R.id.rb3)
    RadioButton rb3;
    @BindView(R.id.rb4)
    RadioButton rb4;
    @BindView(R.id.rb5)
    RadioButton rb5;
    @BindView(R.id.rg)
    RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra1()).commit();
    }

    @OnClick({R.id.rb1, R.id.rb2, R.id.rb3, R.id.rb4, R.id.rb5})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rb1:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra1()).commit();
                break;
            case R.id.rb2:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra2()).commit();
                break;
            case R.id.rb3:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra3()).commit();
                break;
            case R.id.rb4:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra4()).commit();
                break;
            case R.id.rb5:
                getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new fra5()).commit();
                break;
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值