Layoutproblem (Werbung unter Scrollview)

  • 3 Antworten
  • Letztes Antwortdatum
P

PhillippOh

Fortgeschrittenes Mitglied
10
Hey,

ich möchte in meiner Activity ein ScrollView haben und direkt darunter die AdMob Werbung. Bei meiner letzten App war das so, dass das adView den anderen Inhalt (WebView) überlagert hatte, das war aber nicht so schlimm.

Bei meinem jetzigen Projekt stört das aber, wenn die Werbung über Buttosn etc. ist. Die Werbung soll am unteren Bildschirmrand sitzen und das ScrollView soll bis zum adView gehen und dann aufhören.

Hier mal mein Code, bei dem nur das ScrollView auf der kompletten Activity angezeigt wird und die Werbung gar nicht zu sehen ist.

Code:
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        tools:context=".MainActivity" >

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            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" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextView" />

                <EditText
                    android:id="@+id/etEingabe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@layout/rounded_edittext"
                    android:ems="10"
                    android:padding="10dp" >

                    <requestFocus />
                </EditText>

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="TextView" />

                <EditText
                    android:id="@+id/etAusgabe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@layout/rounded_edittext"
                    android:editable="false"
                    android:ems="10"
                    android:padding="10dp" />

                <Button
                    android:id="@+id/btnShort"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5pt"
                    android:layout_marginTop="200pt"
                    android:text="Button" />
            </LinearLayout>
        </ScrollView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             >

            <com.google.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="XXXXX"
                ads:loadAdOnCreate="true"
                ads:testDevices="XXXXX" >
            </com.google.ads.AdView>
        </RelativeLayout>

    </LinearLayout>

Jemand ne Idee?

Gruß
Phillipp
 
Dein Problem könntest Du mit einem negativen Wert in android:layout_marginTop lösen.

Im ScrollView setzt du: android:layout_marginBottom="200dp">
Im darauf folgenden Layout schreibst du: android:layout_marginTop="-200dp"

Hier ein Beispiel:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
     <ScrollView
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_marginBottom="200dp"
           >            
           <LinearLayout
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:orientation="vertical">
           </LinearLayout>
     </ScrollView>
      
     <LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:orientation="vertical"
           android:gravity="bottom" 
           android:layout_marginTop="-200dp"
           >            
           <com.google.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="XXXXX"
                ads:loadAdOnCreate="true"
                ads:testDevices="XXXXX" >
          </com.google.ads.AdView>
     </LinearLayout>
</LinearLayout>
Statt pt solltest du lieber dp (Density-independent pixel) benutzten. So sieht dein Screen bei verschiedenen Displaygrößen gleich aus. Metrics and Grids | Android Developers
 
Habe es nun so gelöst:

Code:
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        tools:context=".MainActivity" >
        
                 <com.google.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="xxxxx"
                ads:loadAdOnCreate="true"
                ads:testDevices="xxxxx" >
            </com.google.ads.AdView>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:layout_alignParentTop="true"
            android:layout_above="@id/adView" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tvInput" />

                <EditText
                    android:id="@+id/etEingabe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@layout/quad_box"
                    android:ems="10"
                    android:padding="10dp" >

                    <requestFocus />
                </EditText>

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="@string/tvOutput" />

                <EditText
                    android:id="@+id/etAusgabe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@layout/quad_box"
                    android:editable="false"
                    android:ems="10"
                    android:padding="10dp" />
                
                <View android:id="@+id/separator" 
                    android:background="#ccc" 
                    android:layout_width = "fill_parent"
                    android:layout_height="1dip"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:layout_centerVertical ="true"
                    android:layout_alignParentTop="true"/>

                <Button
                    android:id="@+id/btnShort"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5pt"
                    android:background="@layout/quad_box_button"
                    android:text="@string/btnShort" />

            </LinearLayout>
        </ScrollView>

       
             

   
        

    </RelativeLayout>

Das mit dem dp habe ich auch vorhin gemerkt.
 
  • Danke
Reaktionen: GENiALi
Die Lösung gefällt mir. Ich werde sie mal ausprobieren.
 
  • Danke
Reaktionen: PhillippOh
Zurück
Oben Unten