首页 > 解决方案 > Admob 横幅隐藏列表视图片段的最后一项

问题描述

我有一个在 activity_main 布局中调用的片段列表视图布局,admob 横幅放置在 activit_main 布局的底部,所以当我向下滚动到列表视图的最后一项时,我发现他被横幅覆盖,这里是完整的活动主布局:

<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">


<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.android.miwok.MainActivity"
    tools:openDrawer="start"
    >


<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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">


        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            >

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/primary_color"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <Button
                    android:id="@+id/more_toolbar"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="end"
                    android:layout_marginEnd="8dp"
                    android:background="@drawable/thumbsuo" />
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                style="@style/CategoryTab"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>


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

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            >
        </android.support.v4.view.ViewPager>


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


    <RelativeLayout
        android:id="@+id/LL_contentProgressBarParent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <ProgressBar
            android:id="@+id/progressBarParent"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:layout_above="@+id/adView"
            android:layout_marginBottom="2dp"

            />

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
            >

        </com.google.android.gms.ads.AdView>


    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/primary_color"
        app:headerLayout="@layout/nav_header"
        app:itemIconTint="@color/text_drawer_color"
        app:itemTextColor="@color/text_drawer_color"
        app:menu="@menu/drawer_menu" />

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

这是 listview_fragment 的完整代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/tan_background"
    >

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:layout_margin="4dp"
        android:layout_above="@+id/banner_layout"

        >

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:background="@color/tan_background"
        android:divider="@color/tan_background"
        android:dividerHeight="8dp"
        android:drawSelectorOnTop="true"
        android:focusable="true"
        android:orientation="vertical"
        android:nestedScrollingEnabled="true"

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



</RelativeLayout>

所以我希望列表视图位于横幅上方,有什么解决方案吗?提前谢谢。

标签: androidandroid-studiolistviewadmobfragment

解决方案


您需要为其设置对齐方式,您的 adview 将始终阻止底部的所有内容,因为您与父底部对齐。

用约束或相对布局(甚至线性布局,它也可以)包装你的 list_view (我假设它是内部视图寻呼机)。然后根据需要对齐它们,将视图寻呼机底部对齐在 adview 顶部,并将 adview 对齐在视图寻呼机下方。

为布局做这样的事情

<CoordinatorLayout..
    <LinearLayout..
        <ViewPager/>
        <AdView wrap content/>
    <LinearLayout/>
<CoordinatorLayout/>

推荐阅读