Android Button below a fixed-size Viewpager

Asked

Viewed 141 times

1

I’m creating a layout where I need a button below Viewpager, in this layout I also click tabs, as in the image below:

inserir a descrição da imagem aqui

What happens is that I can not leave this way without being fixing the size of Viewpager, follows the layout xml.

<?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"/>

The way I did the button is not displayed, how can I fix this? Thank you.

EDITED

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 answer

1


Fala Renan,

Probably not being displayed because you are using Linearlayout on your screen layout.

Try to change it to Relativelayout that he will appear.

Note: If it’s not that, you’d better post all your XML code.

Hugs.

  • Opa Leonardo, I switched to Relativelayout and the button appeared, but the tabs of Tablayout disappeared, I did a test keeping Relativelayout and removing the button and the tabs were still hidden. I edited my question and added all the XML code. Thank you.

  • Add this to your Viewpager android:layout_below="@id/tlTabs" and changes the height to wrap_content

  • It worked perfectly Leonardo, thank you very much.

Browser other questions tagged

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