在选项卡式活动中添加横幅

时间:2017-02-12 10:22:03

标签: android android-fragments android-tabs android-tabbed-activity

我想在Tabbed Activity.Banner中为所有片段添加横幅。页面底部将保持不变。

我的项目中有8个页面,我可以逐个添加横幅给所有碎片。但是在这个方法中,我必须为所有碎片添加8个横幅。我不想要它。我想要一个恒定的横幅底部的所有碎片。

感谢您的帮助:)

enter image description here

这是我的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>

1 个答案:

答案 0 :(得分:1)

尝试替换这个

<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>

这一个

<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>
相关问题