Question

I have a peculiar problem here, I have an activity with relative layout and it has edit text as its child view. It also linear layout as child layout and that linear layout contains a button and a text view. I know this is confusing a bit but I will be providing snapshots for clear understanding and even my activity XML.

The problem I am facing here is when I tap on edit text to enter some text android keyboard gets visible at the bottom of the screen sliding my edit text upwards and my button shifts over my edit text for that moment. When I close the keyboard everything is normal again. I am clueless about why this is happening and may be unaware about the basics with edit text. Here is my XML file...

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    tools:context=".ResultViewActivity"
    android:background="@drawable/background" >

<Button
    android:id="@+id/homeButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/homebtnselectr" />

<EditText
    android:id="@+id/resultEditText"
    android:layout_width="fill_parent"
    android:layout_height="200dip"
    android:layout_alignRight="@+id/homeButton"
    android:layout_centerVertical="true"
    android:background="@drawable/curve_corners"
    android:ems="10"
    android:gravity="top"
    android:inputType="textMultiLine"
    android:overScrollMode="always"
    android:paddingBottom="6dp"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="6dp"
    android:scrollbarStyle="insideInset"
    android:scrollbars="vertical"
    android:text="abcajfklafladfk" 
   />


    <LinearLayout 
        android:id="@+id/get_news_lin_layout"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_alignLeft="@+id/resultEditText"
        android:layout_alignParentBottom="true"
    >

    <Button
        android:id="@+id/getNews"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/getnews_btn_selectr" 
    />
    <TextView
        android:id="@+id/get_news"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Get News"
        android:textSize="20dp"
        android:textStyle="bold" />

    </LinearLayout>
</RelativeLayout>

this is normal activity without keyboard

this is same activity when tapped on edit text and keyboard appears

Was it helpful?

Solution

In your Manifest file : put below line in your activity

android:windowSoftInputMode="adjustPan"

OTHER TIPS

Try adding this line to your LinearLayout

android:layout_below="@+id/resultEditText"

I believe this happens because though your button is in the linear layout the linear layout is a child of the relative layout. End your Relative layout after edittext

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top