0

Hi the following is my layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaaaaa"
    android:id="@+id/mainLayout"       
    android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_marginTop="55dp"
    android:layout_height="wrap_content"
    android:gravity="top">
  <include layout="@layout/search_bar"/> 

  </LinearLayout>
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_gravity="bottom"
    android:orientation="horizontal"
    android:layout_height="50dp"
    android:background="#eeeeee"
    android:gravity="bottom">
    <ImageButton
        android:id="@+id/ImageButton1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginLeft="1dip"
        android:layout_marginRight="1dip"
        android:src="@drawable/appdrawer" />
    </LinearLayout>
    </LinearLayout>

The ImageButton is shown at the bottom when the layout is opened, but when I put the focus on the SearchBox, the keyboard opens and the ImageButton is pushed upwards. How can I make the ImageButton stay as the footer.

hybrid
  • 1,255
  • 2
  • 17
  • 42

5 Answers5

1

You should use Relative Layout instead Linear Layout and Add android: layout_alignParentBottom="true" .

Add set stateHidden|adjustpan android:windowSoftInputMode from activity manifest.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    Thanks , is there any way to do it with LinearLayout itself , the contents in the layout change dynamically in my real app .I am using a Custom View which extends LinearLayout.So I need to achieve this in linearLayout – hybrid Sep 04 '15 at 07:47
1

Here is the layout...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <include
        android:id="@+id/activity_appointment_header"

    // Your header If any
    </include>

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/activity_appointment_header"
        android:layout_marginBottom="65dp"
        android:background="@color/white"
        android:fillViewport="true"
        android:scrollbars="none" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

           // Keep your layout

        </LinearLayout>
    </ScrollView>



    <LinearLayout
        android:id="@+id/ll_book_appointment_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/scroll_view"
        android:layout_alignParentBottom="true"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <View
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@color/cp_red" />

        <Button
            android:id="@+id/btn_book_appointment"
            style="@style/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:text="@string/book_now" />
    </LinearLayout>

</RelativeLayout>

And your activity in should be like this in manifest.xml

 <activity
         android:name=".Activity"

         android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
   </activity>
Vid
  • 1,012
  • 1
  • 14
  • 29
  • Thanks , is there any way to do it with LinearLayout itself , the contents in the layout change dynamically in my real app .I am using a Custom View which extends LinearLayout.So I need to achieve this in linearLayout – hybrid Sep 04 '15 at 10:55
  • Yes, you can do it using weight property in LinearLayout with orientation vertical. – Vid Sep 04 '15 at 11:10
0

Try to add this in your manifest.xml

        <activity
            android:name=".YourActivity"
            android:configChanges="keyboardHidden|keyboard"
            android:windowSoftInputMode="stateHidden|adjustNothing" >
        </activity>
Shishram
  • 1,514
  • 11
  • 20
  • Thanks , but not working . When the keyboard opens , the imagebutton goes up after applying this change also – hybrid Sep 04 '15 at 07:42
0

use android:windowSoftInputMode="adjustPan" to manifest in the corresponding activity:

  <activity android:name="MyActivity"
    ...
    android:windowSoftInputMode="adjustPan"
    ...
  </activity>
Androider
  • 3,833
  • 2
  • 14
  • 24
0

Replace with below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaaaaa"
    android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="55dp"
    android:gravity="top"
    android:orientation="horizontal" >

    <include layout="@layout/search_bar" />
</LinearLayout>

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:background="#eeeeee"
    android:gravity="bottom"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/ImageButton1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginLeft="1dip"
        android:layout_marginRight="1dip"
        android:src="@drawable/appdrawer" />
</LinearLayout>

</LinearLayout>
Jaykumar Donga
  • 380
  • 1
  • 3
  • 18
  • added android:layout_weight="1" to viewpager also add android:windowSoftInputMode="adjustPan|stateHidden" in manifest for relevant activity – Jaykumar Donga Sep 04 '15 at 08:25
  • The problem is that when i click on the edittext for entering search string , the keyboard comes and pushes the imagebutton upward. – hybrid Sep 04 '15 at 08:39