zoukankan      html  css  js  c++  java
  • 4/16学习总结:Fragment

    今天主要学习了有关Fragment的知识

    明天准备继续完善这一部分代码,使其能够显示信息。

    遇到的问题:开始没搞懂逻辑关系,没能将底部按钮与显示内容绑定起来,现已解决

    详情参考:https://www.cnblogs.com/sunxun/p/9241180.html

    在这里做一下总结:

    1.Activity的布局文件分为两部分:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize">
    
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="0dp"
            android:layout_marginEnd="0dp"
            android:background="?android:attr/windowBackground"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/bottom_nav_menu" />
    
        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@id/nav_view"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/mobile_navigation" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>

    下面的按钮部分属于ButtonNavigation部分,上面的内容属于Fragment。

    ButtonNavigation的布局文件通常写在menu中,即menu中定义了各个按钮的布局

    然后添加各个fragment各自的布局文件,在Activity.java中为按钮和界面绑定。

  • 相关阅读:
    Mac Mysql 修改初始化密码
    网址收藏
    Xcode 模拟器复制解决方案
    ios优秀的第三方框架
    CocoaPods第三方库管理工具
    ios网络请求
    java面试宝典
    SQL分表
    FastDFS+Nginx+Module
    分布式文件系统FastDFS架构认知
  • 原文地址:https://www.cnblogs.com/wangzhaojun1670/p/12715066.html
Copyright © 2011-2022 走看看