Tablayout under the actionbar

Asked

Viewed 124 times

0

I’ll use a tablouyt but it sits under the action bar, how to solve this?inserir a descrição da imagem aqui

Xml of the screen

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.TabLayout
    android:id="@+id/tab_Solicitacao"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toTopOf="@+id/pgr_Solicitacao"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

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

<android.support.v4.view.ViewPager
    android:id="@+id/pgr_Solicitacao"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tab_Solicitacao" />

2 answers

2

Apparently you’re wearing a Constraintlayout but the problem is that you are putting all the top layout Constraint as Parent.

Solution

First it is recommended that you use a base style without Action bar as Theme.AppCompat.Light.NoActionBar then add a Toolbar from the v7 support library and then adjust your constraints. Then make the tablayout top Constraint the bottom of Toolbar, so this should be the result:

demo.xml

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/tb1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tb1">

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Left" />

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Center" />

        <android.support.design.widget.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Right" />
    </android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tabLayout" />

</android.support.constraint.ConstraintLayout>

Upshot

Resultado

  • I can’t take the action bar out of every project just because of this screen.

  • then do the same procedure above, but without Toolbar v7

  • was the same way

  • Could send the xml of your complete layout?

  • is complete, only has the setting of the layout Constraint on top of that.

-1

Before, you have to define the type of layout in which these elements will be inserted. Try to put them inside a Relativelayout and indicate to Viewpager that it should be under Tablayout using android:Below="@+id/tab_request" as you can see in the code below. That would go something like this:

<?xml version="1.0" encoding="utf-8"?>

**<RelativeLayout
     android:layout_height="match_parent"
      android:layout_width="match_parent" >**

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_Solicitacao"
        android:below="@+id/tab_solicitacao"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/pgr_Solicitacao"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent">

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pgr_Solicitacao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toBottomOf="@+id/tab_Solicitacao" />

**</RelativeLayout>**
  • The problem is not the layout, the problem is that it is using the tablayout as top Parent layout and not Toolbar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.