RadioButton+Fragment实现简单主页面布局

本文介绍了如何使用RadioButton和Fragment构建简单的主页面布局。在不需要滑动的场景下,这种方式提供了一种替代ViewPager和TabHost的选择。主要内容包括在Framlayout中结合RadioGroup,通过RadioButton切换不同Fragment,并展示了每个Fragment加载不同界面的效果。
摘要由CSDN通过智能技术生成

RadioButton+Fragment实现简单主页面布局

实现主页面布局的方法有不少,很常见的有ViwePager+Fragment,还有TabHost等等,这里因为主页面不需要滑动,也可以用RadioButton+Fragment实现简单的主页布局。为了区分每个页面的不同,随便添加了几个控件,先上效果图:



主页面就是一个Framlayout+RadioGroup,通过点击下边的按钮,切换Fragment。代码非常简单,下面贴出来:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.gechao.materialtabsdemo.MainActivity">

    <FrameLayout
        android:id="@+id/fm"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"></FrameLayout>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#0099FF"
        android:gravity="center_vertical"
        android:orientation="h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值