2017-01-09 43 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

使用框架佈局,而不是線性佈局。框架佈局修復了每個視圖的位置。