Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么我的广告一半在屏幕上,一半在屏幕上?_Android_Android Layout_Adview - Fatal编程技术网

Android 为什么我的广告一半在屏幕上,一半在屏幕上?

Android 为什么我的广告一半在屏幕上,一半在屏幕上?,android,android-layout,adview,Android,Android Layout,Adview,我以编程方式将adview添加到我的应用程序中,并希望在我的回收器视图下添加/删除它(如果用户在应用程序内购买)。我有意将mu Recycler视图和adview放在线性布局(容器)中,我在代码中引用该布局并添加/删除adview。但是,当我尝试它时,我的adview在屏幕上显示了一半,它的右侧有如下空间: 这是我的xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我以编程方式将adview添加到我的应用程序中,并希望在我的回收器视图下添加/删除它(如果用户在应用程序内购买)。我有意将mu Recycler视图和adview放在线性布局(容器)中,我在代码中引用该布局并添加/删除adview。但是,当我尝试它时,我的adview在屏幕上显示了一半,它的右侧有如下空间:

这是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
            xmlns:fab="http://schemas.android.com/apk/res-auto"
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:id="@+id/myMainRelativeLayout"
            android:layout_height="match_parent"
            tools:context=".MainActivity">
<include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar">
</include>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="100"
    android:layout_centerInParent="true"
    android:id="@+id/myAdContainer"
    android:layout_below="@+id/tool_bar">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:focusable="true"
        android:layout_weight="50"
        android:clickable="true"
        android:background="?android:selectableItemBackground"
        android:id="@+id/recyclerView"
    />
</LinearLayout>

<TextView android:id="@+id/list_empty"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="No Shopping Items yet"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true"
    />

    <com.software.shell.fab.ActionButton
        android:id="@+id/buttonFloat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        fab:show_animation="@anim/fab_roll_from_down"
        fab:hide_animation="@anim/fab_roll_to_down"/>

去掉重量和重量总和。

试试这个

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="100"
    android:layout_centerInParent="true"
    android:id="@+id/myAdContainer"
    android:layout_below="@+id/tool_bar">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:focusable="true"
        android:layout_weight="100"
        android:clickable="true"
        android:background="?android:selectableItemBackground"
        android:id="@+id/recyclerView"
    />
</LinearLayout>


我在这里发现的问题是,您为视图组[LinearLayout]分配了100个权重,而视图[RecyclerView]只使用了其中的50个权重。因此,上述利用视图组的整个分配空间的解决方案应该有助于它充分显示视图组。

感谢您的建议,但没有帮助。实际上,移除权重和权重总和会使adview消失。这对我的目的不起作用,因为我不希望我的回收视图占用所有空间。在这种情况下,当我通过代码添加adview时,将根本看不到它。
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="100"
    android:layout_centerInParent="true"
    android:id="@+id/myAdContainer"
    android:layout_below="@+id/tool_bar">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:focusable="true"
        android:layout_weight="50"
        android:clickable="true"
        android:background="?android:selectableItemBackground"
        android:id="@+id/recyclerView"
    />
</LinearLayout>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="100"
    android:layout_centerInParent="true"
    android:id="@+id/myAdContainer"
    android:layout_below="@+id/tool_bar">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:focusable="true"
        android:layout_weight="100"
        android:clickable="true"
        android:background="?android:selectableItemBackground"
        android:id="@+id/recyclerView"
    />
</LinearLayout>