記一次低級錯誤踩坑之旅---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>

 

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