3

I am making a chat application, but happens what when edit text gets focused mean keyboard comes up it hides my header and somehow little bit it is also overlpaping my edit text around 2-4 dp but I don't want this what I want is header should be fixed at top position as it is already implemented in what's app.In what's app when keyboard pops up edit text also goes up respectively of list view and size of list view gets shrinked automatically and header stays all the time... I have tried almost everything according to my little knowledge.I have tried adjust pan , do nothing etc attributes in manifest to that particular activity as it has already been reported many times in stackoverflow but nothing helps me out.Any help please. I also tried this link Push Listview when keyboard appears without adjustPan

here is my xml layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff">

        <RelativeLayout
            android:id="@+id/TopLayout"
            android:layout_width="match_parent"
            android:layout_height="55dp">

            <ImageButton
                android:id="@+id/btn_back"
                android:layout_width="20dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:background="@drawable/back_icon_2x"
                android:textColor="#000000"
                android:textSize="22sp" />

            <LinearLayout
                android:id="@+id/Image"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_toRightOf="@+id/btn_back">

                <Button
                    android:id="@+id/recUserImg"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@drawable/image_circle_shape"
                    android:text=""
                    android:textColor="@color/white"
                    android:visibility="gone" />

                <com.dd.sproutchat.customcontrols.MLRoundedImageView
                    android:id="@+id/userImg"
                    android:layout_width="50dp"
                    android:layout_height="50dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_toLeftOf="@+id/btn_Search"
                android:layout_toRightOf="@+id/Image"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtUserName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="start"
                    android:gravity="left"
                    android:singleLine="true"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@android:color/black" />

                <TextView
                    android:id="@+id/txtOnlineStatus"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="left"
                    android:singleLine="true"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@android:color/black" />
            </LinearLayout>

            <ImageButton
                android:id="@+id/btn_Menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/menu_icon_2x"
                android:visibility="gone" />

            <ImageButton
                android:id="@+id/btn_Search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/search_icon_2x" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rl_line"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_below="@+id/TopLayout"
            android:background="@color/chat_border"></RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rl_Options"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_below="@+id/Rl_line"
            android:background="@color/chat_options_bg">

            <ImageButton
                android:id="@+id/btn_Home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:background="@drawable/home_btn_active_2x" />

            <ImageButton
                android:id="@+id/btn_SproutesList"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:background="@drawable/chat_btn_2x" />

            <ImageButton
                android:id="@+id/btn_Note"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:background="@drawable/note_btn_2x" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rl_line2"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_below="@+id/Rl_Options"
            android:background="@color/chat_border"></RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rl_ChatLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/Rl_MessageLayout"
            android:layout_below="@+id/Rl_line2">

            <!-- android:background="@drawable/chat_bg_2x" -->

            <RelativeLayout
                android:id="@+id/Btn_Chats"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:orientation="horizontal"
                android:weightSum="4">

                <RelativeLayout
                    android:id="@+id/count"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone">

                    <ImageButton
                        android:id="@+id/btn_Sortby"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon_sortby_sprout_2x" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginLeft="20dp"
                        android:layout_marginRight="20dp"
                        android:layout_toLeftOf="@+id/btn_AddSprout"
                        android:layout_toRightOf="@+id/btn_Sortby"
                        android:weightSum="2">

                        <Button
                            android:id="@+id/btn_AllSprouts"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:background="@drawable/btn_blue"
                            android:paddingBottom="3dp"
                            android:paddingLeft="25dp"
                            android:paddingRight="25dp"
                            android:paddingTop="3dp"
                            android:text="@string/AllSprouts"
                            android:textColor="@color/white" />

                        <Button
                            android:id="@+id/btn_AllFavorites"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="30dp"
                            android:layout_weight="1"
                            android:background="@drawable/btn_blank"
                            android:paddingBottom="3dp"
                            android:paddingLeft="15dp"
                            android:paddingRight="15dp"
                            android:paddingTop="3dp"
                            android:text="@string/AllFavorites"
                            android:textColor="@color/grey_start" />
                    </LinearLayout>

                    <ImageButton
                        android:id="@+id/btn_AddSprout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="10dp"
                        android:background="@drawable/icon_add_sprout_2x" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/noteLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:paddingBottom="10dp"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:visibility="gone">

                    <EditText

                        android:id="@+id/searchBar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_toLeftOf="@+id/imageButton4" />

                    <ImageButton
                        android:id="@+id/imageButton4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_toLeftOf="@+id/imageButton5"
                        android:background="@drawable/sort" />

                    <ImageButton
                        android:id="@+id/imageButton5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/add" />
                </RelativeLayout>
            </RelativeLayout>

            <ListView
                android:id="@+id/Lv_Chat"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/Btn_Chats"
                android:divider="@null"
                android:dividerHeight="0dp"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp"
                android:scrollbars="none"
                android:stackFromBottom="true"
                android:transcriptMode="normal"></ListView>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rl_MessageLayout"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:background="@color/chat_screen_bottom">

            <ImageButton
                android:id="@+id/btn_Attachment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:background="@drawable/attachment_icon_white_2x" />

            <EditText
                android:id="@+id/edt_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_toLeftOf="@+id/btn_Send"
                android:layout_toRightOf="@+id/btn_Attachment"
                android:background="@drawable/txt_field"
                android:imeOptions="actionDone"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:singleLine="true"
                    />

            <ImageButton
                android:id="@+id/btn_Send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/icon_send_white_2x" />
        </RelativeLayout>
    </RelativeLayout>

</RelativeLayout>
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • 1
    possible duplicate of [Android: How do I prevent the soft keyboard from pushing my view up?](http://stackoverflow.com/questions/4207880/android-how-do-i-prevent-the-soft-keyboard-from-pushing-my-view-up) – Sharp Edge Aug 26 '15 at 05:53
  • It is not duplicate what I believe because in my case it is vanishing may header part – Abdul Waheed Aug 26 '15 at 06:12
  • Try putting the editext in a linear layout .It should move over soft keyboard.If this doesn't work then adjust your editext's bottom margin or padding programmatically when it gets focused. – Omar Boshra Aug 01 '17 at 10:53

2 Answers2

0

In your AndroidManifest, for this activity add android:windowSoftInputMode="adjustResize"

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

In case mere adjustResize or adjustPan didn't work for you, then try:

android:windowSoftInputMode="stateVisible|adjustPan"

add this to your activity tag in Manifest.xml file and let me know if it works or not.

Sharp Edge
  • 4,144
  • 2
  • 27
  • 41
  • Basically my header layout is relative layout and it contains navigation options and my footer is also relative layout and it contains edit text for typing messages and send button for sending messages but footer part remains on original position but header goes vanish when keyboard poops up I have tries all attributes of windowsofinputmode in manifest still facing the same problem – Abdul Waheed Aug 26 '15 at 06:11
  • @AbdulWaheed can you show a snapshot of this behavior ? – Sharp Edge Aug 26 '15 at 06:13
  • Yes, but how can I attach my snapshot when there is not attachment option available? – Abdul Waheed Aug 26 '15 at 06:16
  • I have been banging my head since yesterday I still have no clue how to fix this issue – Abdul Waheed Aug 26 '15 at 06:49