qq_53978309 2024-02-05 18:21 采纳率: 71.4%
浏览 2

为什么我只是在Fragment_home.xml上设置了头像和昵称,但是其他的页面上也会显示头像和昵称

这个是我登录的主界面,是不是因为我在这里设置了,才会出现问题


<?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"
    android:orientation="vertical"
    tools:context=".SlideActivity">

    <FrameLayout
        android:id="@+id/content"
        android:layout_above="@id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!--导航栏-->
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/navigation" />
    <com.example.hxh.SlideMenu
        android:id="@+id/slideMenu"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--菜单界面的布局-->
        <include layout="@layout/activity_slide_menu"/>
        <!--主界面的布局-->
        <include layout="@layout/fragment_home"/>
    </com.example.hxh.SlideMenu>

</RelativeLayout>
  • 写回答

3条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2024-02-05 18:21
    关注

    引自免费微信小程序:皆我百晓生

    在您的登录主界面布局文件(SlideActivity.xml)中,您包含了fragment_home布局作为SlideMenu的一个子布局。这意味着在滑动菜单布局内,无论何时加载或展示这个主界面,fragment_home中的头像和昵称都会显示出来。

    <com.example.hxh.SlideMenu
        android:id="@+id/slideMenu"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- 其他布局 -->
        <include layout="@layout/fragment_home"/>
    </com.example.hxh.SlideMenu>
    

    如果您不希望在其他页面也显示这些信息,您应该确保每个页面(如Fragment或其他Activity的布局)只包含与该页面相关的UI元素。例如,如果头像和昵称是用户个人主页特有的,那么它们应该只存在于用户的个人主页布局中,而不是全局共享的布局或者主界面布局里。

    要解决这个问题,请从不需要显示头像和昵称的布局中移除或动态控制fragment_home中相应控件的可见性。若是在使用Fragment进行导航时出现此问题,应确保在切换不同Fragment时正确地加载相应的布局文件,而不是在所有Fragment中都包含相同的头像和昵称组件。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月5日