/ / Android tabs Ne pas renseigner les parents - Android, Android-tabs

Onglets Android Ne pas renseigner les parents - Android, android-tabs

J'utilise la bibliothèque de support de conception pour créer des onglets. Dans mon code, mes onglets doivent être fixés et renseignés comme suit:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.ncca_fbla.fabric.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/Toolbar"/>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"  />

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add"
app:fabSize="normal"/>

</android.support.design.widget.CoordinatorLayout>

Cela devrait fonctionner correctement, mais mes onglets ne remplissent pas la barre d’outils:

Les onglets ne se remplissent pas

Que pourrais-je faire de mal?

Réponses:

3 pour la réponse № 1

Changement android:layout_width de votre TabLayout de "wrap_content" à "match_parent"

 <android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>