App底部导航(Fragment与ActivityGroup)

2023-11-23 10:08

本文主要是介绍App底部导航(Fragment与ActivityGroup),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

    Android的3.0版本加入Fragment。在API 13的时候Android就已经将ActivityGroup废弃掉了,并且官方推荐的替代方式就是使用Fragment,因为它使用起来更加的灵活。那么剩下的问题就是如何借助Fragment来完成类似于TabHost一般的效果了,因此我们自然要动起手来了。

》MainActivity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:orientation="vertical" >  
  
    <FrameLayout  
        android:id="@+id/content"  
        android:layout_width="match_parent"  
        android:layout_height="0dp"  
        android:layout_weight="1" >  
    </FrameLayout>  
  
    <LinearLayout  
        android:layout_width="match_parent"  
        android:layout_height="60dp"  
        android:background="@drawable/tab_bg" >  
  
        <RelativeLayout  
            android:id="@+id/message_layout"  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1" >  
  
            <LinearLayout  
                android:layout_width="match_parent"  
                android:layout_height="wrap_content"  
                android:layout_centerVertical="true"  
                android:orientation="vertical" >  
  
                <ImageView  
                    android:id="@+id/message_image"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:src="@drawable/message_unselected" />  
  
                <TextView  
                    android:id="@+id/message_text"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:text="消息"  
                    android:textColor="#82858b" />  
            </LinearLayout>  
        </RelativeLayout>  
  
        <RelativeLayout  
            android:id="@+id/contacts_layout"  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1" >  
  
            <LinearLayout  
                android:layout_width="match_parent"  
                android:layout_height="wrap_content"  
                android:layout_centerVertical="true"  
                android:orientation="vertical" >  
  
                <ImageView  
                    android:id="@+id/contacts_image"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:src="@drawable/contacts_unselected" />  
  
                <TextView  
                    android:id="@+id/contacts_text"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:text="联系人"  
                    android:textColor="#82858b" />  
            </LinearLayout>  
        </RelativeLayout>  
  
        <RelativeLayout  
            android:id="@+id/news_layout"  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1" >  
  
            <LinearLayout  
                android:layout_width="match_parent"  
                android:layout_height="wrap_content"  
                android:layout_centerVertical="true"  
                android:orientation="vertical" >  
  
                <ImageView  
                    android:id="@+id/news_image"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:src="@drawable/news_unselected" />  
  
                <TextView  
                    android:id="@+id/news_text"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:text="动态"  
                    android:textColor="#82858b" />  
            </LinearLayout>  
        </RelativeLayout>  
  
        <RelativeLayout  
            android:id="@+id/setting_layout"  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1" >  
  
            <LinearLayout  
                android:layout_width="match_parent"  
                android:layout_height="wrap_content"  
                android:layout_centerVertical="true"  
                android:orientation="vertical" >  
  
                <ImageView  
                    android:id="@+id/setting_image"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:src="@drawable/setting_unselected" />  
  
                <TextView  
                    android:id="@+id/setting_text"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="center_horizontal"  
                    android:text="设置"  
                    android:textColor="#82858b" />  
            </LinearLayout>  
        </RelativeLayout>  
    </LinearLayout>  
  
</LinearLayout>  


转载地址:http://www.cnblogs.com/android100/p/Android-Fragment-ActivityGroup.html

这篇关于App底部导航(Fragment与ActivityGroup)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/417168

相关文章

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

macOS怎么轻松更换App图标? Mac电脑图标更换指南

《macOS怎么轻松更换App图标?Mac电脑图标更换指南》想要给你的Mac电脑按照自己的喜好来更换App图标?其实非常简单,只需要两步就能搞定,下面我来详细讲解一下... 虽然 MACOS 的个性化定制选项已经「缩水」,不如早期版本那么丰富,www.chinasem.cn但我们仍然可以按照自己的喜好来更换

React实现原生APP切换效果

《React实现原生APP切换效果》最近需要使用Hybrid的方式开发一个APP,交互和原生APP相似并且需要IM通信,本文给大家介绍了使用React实现原生APP切换效果,文中通过代码示例讲解的非常... 目录背景需求概览技术栈实现步骤根据 react-router-dom 文档配置好路由添加过渡动画使用

MFC中App,Doc,MainFrame,View各指针的互相获取

纸上得来终觉浅,为了熟悉获取方法,我建了个SDI。 首先说明这四个类的执行顺序是App->Doc->Main->View 另外添加CDialog类获得各个指针的方法。 多文档的获取有点小区别,有时间也总结一下。 //  App void CSDIApp::OnApp() {      //  App      //  Doc     CDocument *pD

ConstraintLayout布局里的一个属性app:layout_constraintDimensionRatio

ConstraintLayout 这是一个约束布局,可以尽可能的减少布局的嵌套。有一个属性特别好用,可以用来动态限制宽或者高app:layout_constraintDimensionRatio 关于app:layout_constraintDimensionRatio参数 app:layout_constraintDimensionRatio=“h,1:1” 表示高度height是动态变化

ViewPager+fragment实现切换页面(一)

如今的很多应用中都是下面有一排按钮,点击可以切换页面,滑动也可以切换页面。下面就来简单的实现这个功能。 思路 首先肯定是会用到viewpager这个控件,为了能够向下兼容,最好用v4包下的viewpager,Activity要继承FragmentActivity 其次用一个集合来存储所有的fragment页面在设置viewpager的适配器时,把存储fragment页面的list集合传入ada

App Store最低版本要求汇总

1,自此日期起: 2024 年 4 月 29 日 自 2024 年 4 月 29 日起,上传到 App Store Connect 的 App 必须是使用 Xcode 15 为 iOS 17、iPadOS 17、Apple tvOS 17 或 watchOS 10 构建的 App。将 iOS App 提交至 App Store - Apple Developer 2,最低XCode版本 Xcod

安卓中的fragment与viewPager的使用问题的解决

最近使用viewPager,结合fragment使用,发现fragment的周期将不符合他的原有的周期流程,多个fragment将会产生错位问题。       通过研究相关代码,发现fragment的切换实际调用的函数为setUserVisibleHint,通过在其中重写方法,将会达到fragment正确切换的效果。       public void setUserVisible

鸿蒙自动化发布测试版本app

创建API客户端 API客户端是AppGallery Connect用于管理用户访问AppGallery Connect API的身份凭据,您可以给不同角色创建不同的API客户端,使不同角色可以访问对应权限的AppGallery Connect API。在访问某个API前,必须创建有权访问该API的API客户端。 1.登录AppGallery Connect网站,选择“用户与访问”。选择左侧

Xinstall助力App全渠道统计,参数传递下载提升用户体验!

在移动互联网时代,App已成为我们日常生活中不可或缺的一部分。然而,对于App开发者来说,如何有效地推广和运营自己的应用,却是一个不小的挑战。尤其是在面对众多渠道、复杂的数据统计和用户需求多样化的情况下,如何精准地触达目标用户,提升用户的下载、安装和活跃度,更是考验着每一个运营者的智慧。 今天,我们就来揭秘一个能够帮助App开发者解决这些痛点的神器——Xinstall。作为一家一站式App全渠道