Search code examples
androidandroid-layoutandroid-xml

Layout Distorts when keyboard comes up android


I have a simple relative layout containing a textview and two edittext boxes and a button.

When i click on the edittext box the textbox is hidden behind the button.

I don't want my layout to be distorted.

The images are below:

i also added

<activity android:name=".TodoEdit"
            android:windowSoftInputMode="adjustResize">

in the manifest file. Still its getting distored.

The xml file is as follows:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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:background="@drawable/love"
tools:context="com.ashsoftapps.lovecalculator.MainActivity" >

     <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:textSize="30dp"
         android:textStyle="bold" />

     <EditText
         android:id="@+id/editText1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:layout_above="@+id/textView1"
         android:layout_marginBottom="30dp"
         android:ems="10"
         android:hint="Name 1" >

         <requestFocus />
     </EditText>

     <EditText
         android:id="@+id/editText2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"

         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:layout_below="@+id/textView1"
         android:layout_marginTop="15dp"
         android:ems="10"
         android:hint="Name 2" />


   <com.google.android.gms.ads.AdView
     android:id="@+id/adView"
     android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
     ads:adSize="BANNER"
     ads:adUnitId="ca-app" >
 </com.google.android.gms.ads.AdView>

   <ImageButton
       android:id="@+id/imageButton1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_above="@+id/adView"
       android:layout_centerHorizontal="true"
       android:src="@drawable/sub"
       android:visibility="visible" />

image 1

enter image description here


Solution

  • Add this code in your activity tag in your manifest file;

    android:windowSoftInputMode="stateVisible|adjustResize"