2017-01-09 45 views
0

这是我的xml布局,我试图将Adview放置在回收站视图的下方,以便广告不会与回收站视图中的任何项目重叠,但截至目前Adview不是显示。我应该如何放置这些项目,使工具栏位于顶部和底部,使用刷卡刷新监听器进行回收器视图,并在其下方显示AdView和所有这些应该在屏幕上可见。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_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" /> 

+0

裘德嗨,您可以尝试相对布局,而不是使用线性布局。在您的代码中,当您在回收视图中填充信息时,它们没有高度限制,使用相对布局可以设置属性的固定位置。 –

回答

1

最好的办法是让linearlayout由权重

,除以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" /> 

它会为你工作?

只需添加到SwipeRefreshLayout

android:layout_weight="1" 
android:layout_height="0dp" 

并添加到RecyclerView

android:layout_height="match_parent" 

希望工程用U :)

+0

完美的工作,谢谢 –

0

使用框架布局,而不是线性布局。框架布局修复了每个视图的位置。