Search code examples
androidlayoutandroid-edittextscrollviewandroid-relativelayout

background is scrolling it should be constant?


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


Solution

  • 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) ;