记一次低级错误踩坑之旅---fragment不显示

原代码为:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        android:layout_below="@+id/bottomNavigationView"
        />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottomNavigationView"
        app:itemBackground="@color/gray"
        app:itemIconTint="@drawable/main_bottom"
        app:itemTextColor="@drawable/main_bottom"
        app:menu="@menu/menu_bottom_navigation_view"
        android:layout_alignParentBottom="true"
        />


</RelativeLayout>

此时viewpager里面的fragment生命周期代码都走完了,但页面始终不显示出来,后面发现是布局问题,英文单词搞错了,below和above搞反了,此时修改为如下,即可显示:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        android:layout_above="@+id/bottomNavigationView"
        />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottomNavigationView"
        app:itemBackground="@color/gray"
        app:itemIconTint="@drawable/main_bottom"
        app:itemTextColor="@drawable/main_bottom"
        app:menu="@menu/menu_bottom_navigation_view"
        android:layout_alignParentBottom="true"
        />


</RelativeLayout>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章