Android-Fragment动态切换

该博客介绍了如何在Android应用中实现类似微信的底部标签切换内容的效果,通过编写Fragment和相关XML布局文件,实现点击底部标签时动态切换不同的内容界面。主要步骤包括设置项目代码结构、创建Fragment类及布局、编写切换逻辑,并提供了效果图。
摘要由CSDN通过智能技术生成

实现类似微信的效果,点击手机底部的标签时切换至对应的内容界面
思路:

  1. 需要为每个标签设置对应的fragment界面 编写相应的逻辑代码
  2. 点击标签时切换相对应的fragment界面

项目代码结构

1. 编写主界面的xml布局文件

  • activity.main
<?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=".MainActivity">

<!--    展示内容界面-->
    <LinearLayout
        android:id="@+id/content_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"/>

<!--    展示切换标签-->
    <LinearLayout
        android:id="@+id/layout_bottom"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">

        <RadioGroup
            android:id="@+id/rg_home"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_dark"
            android:orientation="horizontal">
            <RadioButton
                android:id="@+id/rb_1"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值