请验证我的布局:底部按钮一直出现在键盘上方

16

我有一个布局几乎做到了我想要的。只有一个关于底部按钮的错误。它应该始终保持在底部。但每当我打开软键盘时,按钮就会显示在键盘上方。这不是我想要的,而是应该被键盘覆盖。

此外,如果您能评论一下布局的构建方式,我会很高兴。

谢谢, steff

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout android:id="@+id/l_layout_tags"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:text="TAGS:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <AutoCompleteTextView android:id="@+id/actv_tags"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:imeOptions="actionDone" />
    <ImageButton android:id="@+id/btn_add_tag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_input_add"
        android:onClick="addTag"/>
</LinearLayout>

<ScrollView android:id="@+id/sv_scroll_contents"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/l_layout_tags"
    android:scrollbarFadeDuration="2000" >
    <TableLayout android:id="@+id/t_layout_contents"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1"
        android:paddingRight="5dip">
        <TableRow android:id="@+id/tr_template">
            <ImageView android:id="@+id/iv_blank"
                android:src="@android:color/transparent" />
            <EditText android:id="@+id/et_content1"
                android:gravity="top"
                android:maxWidth="200dp"
                android:imeOptions="actionDone" />
        </TableRow>
    </TableLayout>
</ScrollView>

<LinearLayout android:id="@+id/l_layout_media_btns"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/sv_scroll_contents" >
    <ImageButton android:id="@+id/btn_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"
        android:onClick="takePicture" />
    <ImageButton android:id="@+id/btn_video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera" />
    <ImageButton android:id="@+id/btn_audio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_btn_speak_now" />
    <ImageButton android:id="@+id/btn_sketch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_edit" />
</LinearLayout> 

<ImageButton android:id="@+id/btn_save_note"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:src="@android:drawable/ic_menu_upload" />

</RelativeLayout>
2个回答

63
android:windowSoftInputMode="adjustPan"添加到AndroidManifest.xml中您的activity标记中。
这样,软键盘不会调整您的布局,您的按钮将留在其下方。 点击 这里 以更好地了解不同的软键盘模式。

你能否评论一下布局本身?它完全是多余的吗?谢谢,伙计。 - stfn
还有一件事:当我填写自动调整大小的EditText(我想要的)时,它在某个时候开始被上述按钮覆盖。 我该如何修改布局,使按钮保持在底部并且不会遮挡任何内容? - stfn
老问题,我知道。但如果您想要保持EditText在底部按钮上方,则可以声明按钮布局layout_alignParentBottom="true"和ScrollView布局layout_above="@id/l_layout_media_btns"以及layout_below。这告诉布局管理器它应该被夹在中间。 - alphonzo79
它限制了滚动操作!!@Dimtar - Arnold Brown
如果是对话框,我有相同的问题吗?如何添加以下代码:android:windowSoftInputMode="adjustPan" - P Rane

2

我曾经遇到过类似的问题,需要始终在屏幕底部显示一个按钮。我通过以下方式解决了按钮被键盘挡住的问题:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" 
   android:background="@color/white"
   android:gravity="center_horizontal"
   >
       <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:layout_gravity="center"
        android:id="@+id/ff"
        >
                 .......
       </ScrollView>

       <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">
            <TextView
            android:id="@+id/txtSigninProblem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:layout_below="@+id/ff"
            android:layout_gravity="bottom|center_horizontal"           
            android:text="Problem Signing in?"
            />
        </LinearLayout>
 </LinearLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接