1

I have an android application. I just added the sample advertisments to my app, and I keep having problems with the ad over my EditText.

When I click on the EditText, the advertisment which is at the bottom of the screen moves up above the keyboard.

My code is below:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    tools:context="org.alexwebber.frc.strongholdcalculator.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/autonomous"
        android:textSize="25sp"
        android:textStyle="bold"
        android:layout_alignParentStart="true"
        android:id="@+id/autoLabel" />

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:id="@+id/autogrid"
        android:layout_below="@+id/autoLabel"
        android:layout_alignParentStart="true"
        android:layout_marginTop="1dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/defreached"
            android:id="@+id/defenseReached"
            android:textSize="17sp"
            android:layout_row="0"
            android:layout_column="0"
            android:layout_columnSpan="13" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/defcrossed"
            android:textSize="17sp"
            android:id="@+id/defcrossed"
            android:layout_row="1"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/lowgoal"
            android:textSize="17sp"
            android:id="@+id/lowgoalauto"
            android:layout_row="2"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/highgoal"
            android:textSize="17sp"
            android:id="@+id/highgoalauto"
            android:layout_row="3"
            android:layout_column="0" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/autodefreach"
            android:textSize="12sp"
            android:layout_row="0"
            android:layout_column="24"
            android:enabled="true"
            android:text="@string/total" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/autodefcross"
            android:textSize="12sp"
            android:enabled="true"
            android:text="@string/total"
            android:layout_row="1"
            android:layout_column="24" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/autolowgoal"
            android:enabled="true"
            android:text="@string/total"
            android:textSize="12sp"
            android:layout_row="2"
            android:layout_column="24" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/autohighgoal"
            android:textSize="12sp"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="3"
            android:layout_column="24" />
    </GridLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/teleop"
        android:id="@+id/teleopLabel"
        android:layout_below="@+id/autogrid"
        android:textSize="25sp"
        android:textStyle="bold"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="0dp" />

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="175dp"
        android:layout_below="@+id/teleopLabel"
        android:layout_alignParentStart="true"
        android:layout_marginTop="1dp"
        android:id="@+id/gridLayout">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/defcrossed"
            android:id="@+id/defcrossedtele"
            android:textSize="17sp"
            android:layout_row="0"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lowgoal"
            android:id="@+id/lowgoaltele"
            android:textSize="17sp"
            android:layout_row="1"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/highgoal"
            android:id="@+id/highgoaltele"
            android:textSize="17sp"
            android:layout_row="2"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/challegedTower"
            android:id="@+id/challengestower"
            android:textSize="17sp"
            android:layout_row="3"
            android:layout_column="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/scaledTower"
            android:id="@+id/scaledtowertele"
            android:textSize="17sp"
            android:layout_row="4"
            android:layout_column="0" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/teledefcross"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="0"
            android:textSize="12sp"
            android:layout_column="13" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/telelowgoal"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="1"
            android:textSize="12sp"
            android:layout_column="13" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/telehighgoal"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="2"
            android:textSize="12sp"
            android:layout_column="13" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/telechallengedtower"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="3"
            android:textSize="12sp"
            android:layout_column="13" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/telescaledtower"
            android:text="@string/total"
            android:enabled="true"
            android:layout_row="4"
            android:textSize="12sp"
            android:layout_column="13" />

    </GridLayout>

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/gridLayout"
        android:id="@+id/rpgrid">
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/breach"
            android:id="@+id/breach"
            android:layout_marginTop="1dp"
            android:checked="false"
            android:layout_row="0"
            android:layout_column="0"
            android:layout_below="@+id/gridLayout"/>

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/capture"
            android:id="@+id/captured"
            android:layout_marginTop="1dp"
            android:checked="false"
            android:layout_row="0"
            android:layout_column="1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/calculate"
            android:id="@+id/button"
            android:textSize="20sp"
            android:layout_row="1"
            android:layout_column="0"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="@string/totalscore"
            android:textSize="20sp"
            android:id="@+id/total"
            android:layout_row="1"
            android:layout_column="1"
            android:layout_gravity="right" />
    </GridLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:windowSoftInputMode="adjustPan"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>
Alex Webber
  • 93
  • 2
  • 10

2 Answers2

1

It moves up and overlaps EditText because you set alignParentBottom="true", thus when keyboard shows up, the layout parent bottom is the top of the SoftKeyboard.

You should probably get the solution by adding the all content above the AdView and by calling adjustResize on the Activity declaration in Manifest. On a side note, I'm not sure that calling android:windowSoftInputMode="adjustPan" in AdView xml's widget is going to do something...

Therefore, to handle this behaviour, put the AdView at the top of layout's container and declare a sub-container for the rest of content:

<RelativeLayout ...>
    <AdView
        android:id="@+id/adView"
        android:layout_alignParentBottom="true"
        ... />
    <RelativeLayout
        android:layout_above="@id/adView"
        ...>
        <TextView ...>
        <GridLayout ...>
        <GridLayout ...>
    </RelativeLayout>
</RelativeLayout>

Then, make the layout adjusting when keyboard shows up in Manifest.xml:

<activity
    android:windowSoftInputMode="adjustResize"
    ... />

This should work as expected on similar answer. Also, there is another workaround: dynamically detect when the Keyboard is showing up and make the AdView invisible, and vice versa, but I think it does too much hard code than resolved into layout.

Community
  • 1
  • 1
Blo
  • 11,903
  • 5
  • 45
  • 99
0

Have you set adjustResize for windowSoftInputMode in your Manifest file? this will cause your UI layout to resize when the input method popup. if you don't want to resize, remove it.

    <activity
        android:name=".TestActivity"
        android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
        android:label="@string/app_name" >
    </activity>

http://developer.android.com/training/keyboard-input/visibility.html#Respond

zdd
  • 8,258
  • 8
  • 46
  • 75