Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parent bottom views hide with parent center layout view on opening keyboard

Tags:

android

I am working on layout where I have aligned one cardview on the center of the screen and contact us button on bottom of the screen. This layout looks OK when keyboard is closed.

It looks like below :-enter image description here

layout.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:weightSum="2">

                <ImageView
                    android:id="@+id/login_image"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@drawable/login_background" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/grey_background" />

            </LinearLayout>


            <android.support.v7.widget.CardView
                android:id="@+id/media_card_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                card_view:cardBackgroundColor="@color/white"
                card_view:cardElevation="4dp"
                card_view:cardCornerRadius="5dp"
                >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    >

                    <ImageView
                        android:id="@+id/logoImageView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:background="@color/grey_background"
                        android:padding="15dp"
                        android:src="@drawable/logo_login"
                        />

                    <EditText
                        android:id="@+id/usertext"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_below="@id/logoImageView"
                        android:layout_marginLeft="20dp"
                        android:layout_marginRight="20dp"
                        android:layout_marginTop="20dp"
                        android:background="@drawable/edittext_background"
                        android:hint="User ID"
                        android:maxLength="50"
                        android:padding="10dp"
                        android:singleLine="true"
                        android:textColorHint="@color/hint_text_color"
                        android:textSize="16sp" />


                    <FrameLayout
                        android:id="@+id/passwordLayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/usertext"
                        android:layout_marginTop="8dp"
                        android:orientation="horizontal">

                        <EditText
                            android:id="@+id/passtext"
                            android:layout_width="match_parent"
                            android:layout_height="40dp"
                            android:layout_marginLeft="20dp"
                            android:layout_marginRight="20dp"
                            android:background="@drawable/edittext_background"
                            android:fontFamily="sans-serif"
                            android:hint="@string/password"
                            android:inputType="textPassword"
                            android:maxLength="50"
                            android:padding="10dp"
                            android:singleLine="true"
                            android:textColorHint="@color/hint_text_color"
                            android:textSize="16sp" />

                        <ImageView
                            android:id="@+id/passwordeye"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="right|center_vertical"
                            android:padding="8dp"
                            android:layout_marginRight="25dp"
                            android:src="@drawable/eye_close" />

                    </FrameLayout>

                    <LinearLayout
                        android:id="@+id/termsLayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/passwordLayout"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="20dp"
                        android:layout_marginTop="15dp"
                        android:gravity="center"
                        android:orientation="horizontal">


                        <ImageView
                            android:id="@+id/check_box"
                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"
                            android:padding="5dp"
                            android:src="@drawable/checkbox_checked" />

                        <TextView
                            android:id="@+id/terms_and_cond"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:textColor="@color/black"
                            android:textColorLink="#80000000"
                            android:textSize="13sp" />
                    </LinearLayout>

                    <View
                        android:id="@+id/lineView"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_below="@id/termsLayout"
                        android:layout_marginTop="15dp"
                        android:background="@color/grey_background" />

                    <LinearLayout
                        android:id="@+id/newuser_login_layout"
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:background="@color/dark_grey"
                        android:layout_below="@id/lineView"
                        android:orientation="horizontal">


                        <TextView
                            android:id="@+id/newUserButton"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="@drawable/translucent_round_button"
                            android:gravity="center"
                            android:text="New User ?"
                            android:textColor="@color/grey_text_color"
                            android:textSize="17sp" />

                        <TextView
                            android:id="@+id/loginbutton"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="@drawable/bottom_round_button"
                            android:gravity="center"
                            android:text="Login"
                            android:textColor="@color/white"
                            android:textSize="17sp" />

                    </LinearLayout>
                </RelativeLayout>
            </android.support.v7.widget.CardView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_gravity="center"
                android:gravity="center"
                android:orientation="vertical">


                <TextView
                    android:id="@+id/contactus_button"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="15dp"
                    android:background="@drawable/contact_us_selector"
                    android:drawableLeft="@drawable/contact_us_green"
                    android:drawablePadding="5dp"
                    android:gravity="center"
                    android:padding="8dp"
                    android:text="Contact Us"
                    android:textColor="@color/black" />

                <TextView
                    android:id="@+id/textviewone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:gravity="center"
                    android:textColor="@color/black"
                    android:textColorLink="#80000000"
                    android:textSize="13sp" />

            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/snackbarCoordinatorLayout"
        android:layout_width="match_parent"

        android:layout_height="match_parent"
        >

    </android.support.design.widget.CoordinatorLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/android:progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone" />
</FrameLayout>

Question :-

When keyboard opens then contact us button and text which is at the bottom of above screen hide behind the center layout. I want it should not be hide, on opening keyboard screen should be scroll and contact us button should be at the bottom.

On opening keyboard it looks like :-

enter image description here

like image 410
N Sharma Avatar asked Aug 06 '16 09:08

N Sharma


People also ask

How do you fix the bottom button on a linear layout?

On a LinearLayout, place it at the bottom and make sure to set the elements layout_weight properly. Show activity on this post. Set android:layout_gravity="bottom" . Hope this helps.

How do you set a view at the bottom of a linear layout?

You will have to expand one of your upper views to fill the remaining space by setting android:layout_weight="1" on it. This will push your last view down to the bottom.


1 Answers

Just a single line to be added...

Add android:windowSoftInputMode="stateHidden|adjustPan" in required activity of your manifest file.

like image 99
Naveen Kumar M Avatar answered Sep 19 '22 11:09

Naveen Kumar M