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

相关文章

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

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