Search code examples
androidandroid-fragmentsandroid-tabsandroid-tabbed-activity

Add banner in tabbed activity


I want to add a banner for all fragments in my Tabbed Activity.Banner will be constant at bottom of the page.

I have 8 page in my project, i can add a banner one by one to all fragments.But at this method, i have to add 8 banner for all fragments.I do not want it.I want a constant banner upon all fragments at the bottom.

Thanks for help :)

enter image description here

here is my main_activity.xml ;

<android.support.design.widget.CoordinatorLayout
    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"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.aslan.rte3.MainActivity">




    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:background="@android:color/black">

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

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


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

    </android.support.v4.view.ViewPager>






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

Solution

  • Try to replace this one

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

    by this one

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:background="#E0DFDE">
    
        <FrameLayout
            android:id="@+id/banner_layout"
            android:layout_width="match_parent"
            android:layout_height="50dp">
            <!-- put your banner here -->
        </FrameLayout>
    </LinearLayout>