Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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 XML布局无法正确显示视图_Android_Xml_Android Layout_Admob - Fatal编程技术网

Android XML布局无法正确显示视图

Android XML布局无法正确显示视图,android,xml,android-layout,admob,Android,Xml,Android Layout,Admob,这是我的xml布局,我正在尝试将Adview放置在recycler视图的下方,以便广告不会与recycler视图上的任何项目重叠,但到目前为止,Adview未显示。我应该如何确切地放置项目,使工具栏位于具有滑动刷新侦听器的recycler视图的顶部和底部,并使Adview和所有项目都位于下方在屏幕上浏览 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.andro

这是我的xml布局,我正在尝试将Adview放置在recycler视图的下方,以便广告不会与recycler视图上的任何项目重叠,但到目前为止,Adview未显示。我应该如何确切地放置项目,使工具栏位于具有滑动刷新侦听器的recycler视图的顶部和底部,并使Adview和所有项目都位于下方在屏幕上浏览

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_recipe_results2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:titleTextColor="@color/textIcons" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/pull_to_refresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:fadingEdge="none" />

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

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER" />


使用框架布局而不是线性布局。框架布局固定每个视图的位置。

最好的方法是将
线性布局除以权重

XML
布局转换为以下格式:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_recipe_results2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:titleTextColor="@color/textIcons" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/pull_to_refresh"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:fadingEdge="none" />

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

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER" />
并将其添加到
RecyclerView

android:layout_height="match_parent"

“希望”与u:)

您好,jude,您可以尝试相对布局,而不是使用线性布局。在代码中,当您在循环视图中填充信息时,它们的高度没有限制,使用相对布局可以设置属性的固定位置。
android:layout_height="match_parent"