2016-06-30 9 views
5

Ich habe eine RelativeLayout in denen ich eine RecyclerView und eine LinearLayout mit einer AdView innen haben. Die RecyclerView hat viele Elemente und wenn ich nicht in der Lage war, sie auf dem Bildschirm zu zeigen, musste ich nur nach unten scrollen, um sie zu sehen, aber jetzt, dass ich die LinearLayout am unteren Rand des Bildschirms mit der innen hinzugefügt habe, scrolle ich nach unten und I ' Ich kann das letzte Element der RecyclerView nicht sehen. Ich befestige die LinearLayout auf der Unterseite, aber es scheint, dass es über der RecyclerView ist und ich möchte die RecyclerView Elemente auf dem Bildschirm zeigen, aber nicht hinter der LinearLayout. Ist es möglich?AdView an der Unterseite angebracht lassen mich nicht letzten Artikel in Recyclerview

Hier ist meine XML für das Layout:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:ads="http://schemas.android.com/apk/res-auto"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rvGeneric" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical"> 
</android.support.v7.widget.RecyclerView> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:gravity="center"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adViewBaseRefresh" 
     android:layout_width="fill_parent" 
     android:layout_height="53dp" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id" 
     android:layout_marginBottom="3dp"> 
    </com.google.android.gms.ads.AdView> 

</LinearLayout> 

+0

für das, was Ihr tun Sie es so gut kann ändern Linearlayout, und legen Sie Gewicht für t er adView an der Unterseite – Geoff

+0

@ Geoff das Gewicht? Wie mache ich das? – Nahue

+0

android: layout_weight = "0.1" – Geoff

Antwort

3

Eine relative Layout muss "Relativ" Beziehungen innerhalb der XML definiert. Wie Sie keine haben (außer das lineare Layout auf der Unterseite ausrichten), das Ergebnis ist die LL und RecyclerView sind überlappend.

die Linie android hinzufügen: layout_below = "@ id/rvGeneric" an den linearen Layout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:ads="http://schemas.android.com/apk/res-auto"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/ll_ad" 
     android:layout_alignParentBottom="true" 
     android:gravity="center"> 

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adViewBaseRefresh" 
      android:layout_width="fill_parent" 
      android:layout_height="53dp" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id" 
      android:layout_marginBottom="3dp"> 
     </com.google.android.gms.ads.AdView> 

    </LinearLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvGeneric" 
     android:layout_above="@id/ll_ad" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical"/> 

</RelativeLayout> 
+0

Hallo, vielen Dank für die Antwort! Ich habe es gerade versucht, aber es hat nicht funktioniert. Was könnte sonst noch falsch sein? – Nahue

+0

Geoffs Antwort auf ein LinearLayout ist wahrscheinlich einfacher ... aber ich habe auch meine bearbeitet, um für das RelativeLayout zu arbeiten. Das Linearlayout wird jetzt zuerst definiert, dann können RecyclerView - RelativeLayout-Inhalte schwierig sein, um richtig zu werden. – FishStix

+0

Dieser hat perfekt funktioniert, danke! – Nahue

0

dieses Denn ich persönlich ein Linearlayout wie unten verwenden würde:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    tools:context="com.example.geoff.stackoverflowtesting.MainActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/rvGeneric" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="TESTING2" 
       android:background="#FFF000" 
       android:textSize="200dp" 
       android:scrollbars="vertical"> 
      </TextView> 
     </LinearLayout> 
    </ScrollView> 
    <TextView 
     android:id="@+id/adViewBaseRefresh" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TESTING" 
     android:textSize="30dp" 
     android:textColor="#FFF000" 
     android:background="#000000" 
     android:layout_marginBottom="3dp" 
     android:layout_weight="0.1"> 
    </TextView> 
</LinearLayout> 

Wenn Sie besonders wollen eine RelativeLayout verwenden dann:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    tools:context="com.gfaiers.layoutexamples.MainActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/rvGeneric" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical"> 
      </android.support.v7.widget.RecyclerView> 
     </LinearLayout> 
    </ScrollView> 
    <com.google.android.gms.ads.AdView 
     android:id="@+id/adViewBaseRefresh" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id" 
     android:layout_marginBottom="3dp"> 
    </com.google.android.gms.ads.AdView> 
</RelativeLayout> 
+0

Hallo Geoff, beide Codes funktionieren nicht = ( – Nahue

+0

) Lass mich einfach Android Studio hochfahren, ich werde ihnen einen Test geben und es für dich holen. Ugh, hab ein riesiges Update dafür ... Gib mir einen während. – Geoff

+0

Entschuldigung für die Verzögerung, musste große Aktualisierung tun. Ich habe gerade # 1 getestet und es funktioniert für mich, ich habe den Code aktualisiert, um zu zeigen, was ich dafür habe.Wie Sie sehen können, wenn Sie dies ausführen Die schwarz-gelbe Test-Textansicht wird unten angeheftet und benötigt so viel Platz wie nötig, um den Rest des Scrollview zu erhalten.Sie können immer noch den gesamten Inhalt von oben anzeigen, da Sie nur nach oben/unten scrollen müssen. – Geoff