-1

I have designed the login layout as follows

<?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"
    android:background="@drawable/login_bg">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none">

        <LinearLayout
            android:id="@+id/login_fields_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="20dp">

            <ImageView
                android:id="@+id/loginLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingTop="30dp"
                android:src="@drawable/logo" />

            <EditText
                android:id="@+id/userNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="80dp"
                android:background="@drawable/textfield"
                android:drawableLeft="@drawable/username"
                android:drawablePadding="10dip"
                android:hint="@string/hint_username"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:maxLength="50"
                android:padding="10dp"
                android:singleLine="true"
                android:textColor="@color/login_textcolor"
                android:textCursorDrawable="@null" />

            <EditText
                android:id="@+id/passwordEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:background="@drawable/textfield"
                android:drawableLeft="@drawable/password"
                android:drawablePadding="10dip"
                android:hint="@string/hint_password"
                android:imeOptions="actionNext"
                android:inputType="textPassword"
                android:padding="10dp"
                android:singleLine="true"
                android:textColor="@color/login_textcolor"
                android:textCursorDrawable="@null" />


            <LinearLayout
                android:id="@+id/loginOptionsLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="2">

                <CheckBox
                    android:id="@+id/rememberMeCheckBox"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:button="@null"
                    android:checked="false"
                    android:drawableEnd="@drawable/bg_checkbox"
                    android:gravity="center_vertical"
                    android:paddingRight="40dp"
                    android:text="@string/text_rememberme"
                    android:textColor="@color/login_textcolor"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/forgotPasswordButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@null"
                    android:gravity="right|center_vertical"
                    android:singleLine="true"
                    android:text="@string/text_forgotpassword"
                    android:textColor="@color/login_textcolor"
                    android:textSize="14sp" />

            </LinearLayout>

            <Button
                android:id="@+id/loginButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:background="@drawable/button_bg"
                android:text="@string/text_login"
                android:textColor="@android:color/white"
                android:textSize="20dp"
                android:textStyle="bold" />`
        </LinearLayout>


    </ScrollView>

</RelativeLayout>

when the i touched on the edittext the background is moving up it need to be constant as it is outside the scrollview.How to solve this issue.

i have referred the following Background Image Placement as in this they need in the bottom corner i need it as background.but anyway with curiosity i tried it but still it is scrolling the background

Community
  • 1
  • 1
Harish
  • 3,122
  • 2
  • 31
  • 46
  • possible duplicate of [Background Image Placement](http://stackoverflow.com/questions/2781593/background-image-placement) – nkorth Aug 21 '15 at 10:18
  • @nkorth That is located in the lower left corner.In my scenario it is for whole background. – Harish Aug 21 '15 at 10:20
  • Yes, you can use the same technique to anchor your whole background to, say, the top edge. I think what's happening in your case is: the background is anchored to the center by default, meaning when the viewport shrinks (because of the keyboard), the background appears to move. If the background was anchored to the top, then a height change would not move the background. – nkorth Aug 21 '15 at 10:55
  • i tried that too it is not working it is taking the background more top.it should not move up background should be constant. – Harish Aug 21 '15 at 11:11
  • @nkorth could you try the code and then press up and down arrows.The answer which annitha Manikandan is given it is working. – Harish Aug 21 '15 at 11:15
  • I think I must be completely misunderstanding what you're trying to accomplish. Sorry. Your wording is very unclear. – nkorth Aug 21 '15 at 11:17
  • without understanding why you are pressing down arrows. – Harish Aug 21 '15 at 11:20

2 Answers2

0

I tried it and it works. Remove the background from xml layout

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getWindow().setBackgroundDrawableResource(R.drawable.login_bg) ;
Anitha Manikandan
  • 1,160
  • 7
  • 19
  • Could you explain why a change to the SoftInputMode is necessary? Code without explanation isn't a useful answer for people who find this in the future, and may not even be a useful answer now either. – nkorth Aug 21 '15 at 10:57
  • softInputMode matters because when we click on the EditText, the keypad opens. The background change is due to the change in window size and position. So we are setting background to the window itself and controlling the change in window screen size. – Anitha Manikandan Aug 21 '15 at 11:01
  • Making the screen not resize could have other side effects, including hiding content from the user. Setting `SOFT_INPUT_STATE_ALWAYS_HIDDEN` seems like an even worse idea. – nkorth Aug 21 '15 at 11:04
  • In certain layouts, this would be the solution. And specifically for this layout, I could scroll to up and down extremes and the content is all well displayed! – Anitha Manikandan Aug 21 '15 at 11:07
  • This is working fine for me. thanks @AnithaManikandan. – Harish Aug 21 '15 at 11:13
-1

Use the following in your activity

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Anitha Manikandan
  • 1,160
  • 7
  • 19
  • I tried the above statement if i use it the screen is not scrolling.background should not scroll.But screen should scroll. – Harish Aug 21 '15 at 10:15