В моем приложении я хочу использовать представление BottomNavigationView
чтобы показать некоторые фрагменты. У меня есть 4 fragments
и я устанавливаю эти fragments
в BottomNavigationView
.
Я пишу приведенные ниже коды, но на больших экранах устройств, таких как таблицы, эти элементы отображаются в центре BottomNavigationView
.
такой как изображение ниже:
Но я хочу показать это заполнение элементов BottomNavigationView
, таких как изображение ниже:
Мои коды XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/container"
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"
tools:context=".MainActivity">
<fragment
android:id="@+id/mainNavigationFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
android:layout_above="@+id/bottomNavigationView"
app:navGraph="@navigation/navigation_graph"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation"/>
</RelativeLayout>
Как я могу изменить свои коды для элементов шоу, таких как изображение два?
Попробуйте использовать ConstraintLayout
и посмотрите, решена ли проблема
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
app:labelVisibilityMode="labeled"
android:id="@+id/bottomNavigationView"
app:menu="@menu/navigation_manager"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/navigation_graph"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"/>
</android.support.constraint.ConstraintLayout>