前言
今天我想与大家分享一些关于如何利用fragment实现仿微信APP的经验。作为社交领域最受欢迎、功能齐全且可扩展性强的应用之一,微信APP在浏览器首页和个人中心之上还有一个重要部分:底部导航栏。本文将介绍如何使用fragment来创建类似的底部导航菜单,并显示不同屏幕元素。通过学习以下内容,你将掌握以下技能:
目录
一、Android Studio简介
在Android应用领域,Android Studio已被广泛认可为最好的开发工具之一。通过参加这门课程,我得以系统地学习并了解如何使用Android Studio来构建高效、用户友好和不易出错的安卓应用程序。以下是我的心得分享:
二、学期知识汇总
经过一个学期时间的学习,学习到了很多关于Android studio的知识,比如实现项目跳转;如何仿造QQ相册,制作一个简易版的QQ相册;如何制作一个简易版的计算器;如何完成登陆与注册页面......今天我来讲讲我从Android studio里学到的Fragment方法仿写首页跟通讯录界面设计。
三、fragment概述
fragment是一种控制器对象,activity可委派它完成一些任务,通常这些任务就是管理用户界面,受管理的用户界面可以是一整屏或是整屏的一部分,管理用户界面的fragment又称Ul fragment 它也有自己的布局文件视图,fragment视图包含了用户可以交互的可视化的UI元素,activity视图含有可供fragment视图插入的位置,如果有多个fragment要插入,activity视图也可以提供多个位置。
四、实现步骤
- 底部导航栏
- 先建几个Fragment
- 微信首页WxFragment
- 通讯录TxlFragment
- 发现FxFragment
- 个人中心WFragment
- 先在activity_main2.xml里添加如下布局文件,图片按钮ImageButton和布局管理器
<?xml version="1.0" encoding="utf-8"?>
<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:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="19"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="微信"
android:textSize="25dp"
android:gravity="center"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/fm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="19"
>
<ImageButton
android:id="@+id/wx"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_weight="1"
android:src="@drawable/weixin2"
android:text="微信"
android:background="@color/black"
/>
<ImageButton
android:id="@+id/txl"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_weight="1"
android:text="通讯录"
android:src="@drawable/tongxulu2"
android:background="@color/black"
/>
<ImageButton
android:id="@+id/fx"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_weight="1"
android:text="发现"
android:src="@drawable/faxian2"
android:background="@color/black"
/>
<ImageButton
android:id="@+id/w"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_weight="1"
android:text