1

Estou criando um layout onde preciso de um botão abaixo do ViewPager, neste layout eu também carregos abas, como na imagem abaixo:

inserir a descrição da imagem aqui

O que ocorre é que não consigo deixar desta forma sem ser fixando o tamanho do ViewPager, segue o xml do layout.

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

<android.support.design.widget.TabLayout
    android:id="@+id/tlTabs"
    app:tabGravity="fill"
    app:tabIndicatorColor="@color/orange"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/orange"
    app:tabTextColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/azulForte">
</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/vpPager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>

<Button
    android:layout_width="wrap_content"
    android:layout_height="67dp"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_gravity="center_horizontal"/>

Da forma que fiz o botão não é exibido, como posso corrigir isto? Obrigado.

EDITADO

Layout MainActivity

<LinearLayout
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"
android:fitsSystemWindows="true"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/orange"
    android:id="@+id/toolbar"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:title="Drawer With Swipe Tabs" />

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/drawerLayout">

    <FrameLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containerView">
    </FrameLayout>

    <android.support.design.widget.NavigationView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/shitstuff"
        app:itemTextColor="@color/black"
        app:menu="@menu/drawermenu"
        android:layout_marginTop="-24dp"
        />

</android.support.v4.widget.DrawerLayout>

Layout Fragment Tab

<?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"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            tools:context=".fragments.TabFragment">

<android.support.design.widget.TabLayout
    android:id="@+id/tlTabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/azulForte"
    app:tabGravity="fill"
    app:tabIndicatorColor="@color/orange"
    app:tabMode="scrollable"
    app:tabSelectedTextColor="@color/orange"
    app:tabTextColor="@color/white">
</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/vpPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v4.view.ViewPager>

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="67dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:text="New Button"/>
</RelativeLayout>

1 Resposta 1

1

Fala Renan,

Provavelmente não está sendo exibido por que você está usando LinearLayout no seu layout da tela.

Tente alterá-lo para RelativeLayout que ele vai aparecer.

Obs: Se não for isso, é melhor você postar o código todo do seu XML.

Abraços.

3
  • Opa Leonardo, eu mudei para o RelativeLayout e o botão apareceu, porém as abas do TabLayout sumiram, eu fiz um teste mantendo RelativeLayout e removendo o botão e as abas ainda continuavam escondidas. Eu editei minha pergunta e adicionei todo o código do XML. Obrigado. 10/08/2016 às 19:32
  • Adiciona isso aqui no seu ViewPager android:layout_below="@id/tlTabs" e altera o height para wrap_content 10/08/2016 às 19:37
  • Funcionou perfeitamente Leonardo, muito obrigado. 10/08/2016 às 19:44

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .