【问题标题】:Add banner in tabbed activity在选项卡式活动中添加横幅
【发布时间】:2017-02-12 10:22:02
【问题描述】:

我想为我的选项卡式活动中的所有片段添加横幅。横幅将在页面底部保持不变。

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

感谢您的帮助:)

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

【问题讨论】:

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


    【解决方案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>
    

    【讨论】:

    • 我这样做了,但它对我不起作用,它在我的屏幕上显示空白页。框架布局始终在顶部,我无法更改其位置。控制台说;没有足够的空间来展示广告。需要 320x50 dp,但只有 320x0 dp。
    • 能否提供您的活动布局?
    • 我已将我的 xlm 文件添加到问题中
    • 天啊!!!它的工作:) 我非常尊重你先生。:):):) 请接受我的感谢谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多