2

I have an edittext, and when I focus on that, the footer layout was pushed together. How to hide footer when focus on edittext.

Before focus

Before Focus

After focus

After Focus

this is my source code

<ListView
    android:id="@+id/list_chat_rom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/rl_footer_send"
    android:divider="@android:color/transparent"
    android:dividerHeight="5dp"></ListView>

<RelativeLayout
    android:id="@+id/rl_footer_send"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/menu_bar_bg">

    <RelativeLayout
        android:id="@+id/rl_insert_chat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingTop="10dp">
        <ImageView
            android:id="@+id/btn_send_msg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/layout_imv_send_message" />

        <EditText
            android:id="@+id/edit_insert_chat"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@id/btn_send_msg"
            android:background="@drawable/layout_edit_text_chat"
            android:hint="type to filter"
            android:inputType="text"
            android:maxLines="1"
            android:textColor="@color/black" />
    </RelativeLayout>

    <View
        android:id="@+id/view_line"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_below="@id/rl_insert_chat"
        android:background="@color/black"></View>

    <RelativeLayout
        android:id="@+id/rl_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/view_line"
        android:paddingBottom="5dp"
        android:paddingLeft="20dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp">

        <ImageView
            android:id="@+id/imv_avatar_chat"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <RelativeLayout
            android:id="@+id/rl_content_home"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/imv_avatar_chat">

            <TextView
                android:id="@+id/tv_name_user"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="user name"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/tv_level"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_name_user"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:text="lv : 10"
                android:textColor="@color/white" />


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true"
                android:layout_marginRight="10dp"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="5dp"
                        android:src="@drawable/target_icon" />

                    <TextView
                        android:id="@+id/tv_point_show"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="10/125" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:paddingTop="10dp">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="5dp"
                        android:src="@drawable/gem_icon" />

                    <TextView
                        android:id="@+id/tv_xu_show"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:text="100" />
                </LinearLayout>

            </LinearLayout>


        </RelativeLayout>

        <TextView
            android:id="@+id/tv_login_facebook"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@id/imv_avatar_home"
            android:text="ĐĂNG NHẬP BẰNG FACEBOOK"
            android:visibility="gone" />

    </RelativeLayout>
</RelativeLayout>

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
luckymancvp
  • 97
  • 1
  • 5

2 Answers2

3

Why don't you try to hide it?
You can try to detect the keyboard state with this :

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
            ... do something here
        }
     }
});

Note : Taken from here

And then you just hide the view that you want to hide.

Community
  • 1
  • 1
Niko Adrianus Yuwono
  • 11,012
  • 8
  • 42
  • 64
0

Try with

android:windowSoftInputMode="adjustPan" 

in the Activity declaration in the manifest

momo
  • 3,404
  • 6
  • 37
  • 66