如何在布局底部放置一个按钮,使其即使在键盘打开时也能保持在那里?

时间:2015-09-04 06:02:46

标签: android android-layout

以下是我的布局

mod_env is enabled

当打开布局时,ImageButton会显示在底部,但是当我将焦点放在SearchBox上时,键盘会打开并向上推动ImageButton。如何使ImageButton保持为页脚。

5 个答案:

答案 0 :(得分:1)

您应该使用相对布局而不是线性布局并添加android: layout_alignParentBottom="true"

从活动清单中添加集stateHidden|adjustpan android:windowSoftInputMode

答案 1 :(得分:1)

这是布局......

<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>

您的活动在manifest.xml

中应该是这样的
 <activity
         android:name=".Activity"

         android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
   </activity>

答案 2 :(得分:0)

尝试在manifest.xml

中添加此内容
        <activity
            android:name=".YourActivity"
            android:configChanges="keyboardHidden|keyboard"
            android:windowSoftInputMode="stateHidden|adjustNothing" >
        </activity>

答案 3 :(得分:0)

使用android:windowSoftInputMode =&#34; adjustPan&#34;在相应的活动中表现出来:

  <activity android:name="MyActivity"
    ...
    android:windowSoftInputMode="adjustPan"
    ...
  </activity>

答案 4 :(得分:0)

替换为以下

<?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>