Android:如何避免在调用键盘时推送布局

Jay*_*ayu 4 xml keyboard layout android android-edittext

我的布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <Button android:text="Button" android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
<ImageButton android:id="@+id/imageButton1" android:src="@android:drawable/stat_notify_sync_noanim" android:layout_height="fill_parent" android:layout_weight="1" android:layout_width="fill_parent"></ImageButton>
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="match_parent">
    <requestFocus></requestFocus>
</EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

当通过点击编辑文本调用软键盘时,整个窗口被推动.我可以保持标题上的按钮固定,让imageview被推?因为按钮会像导航栏一样,所以即使布局被推高,它也应该存在.

之前 在此输入图像描述

在此输入图像描述

ani*_*nia 11

阅读这里的文章:http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
您应该在您的活动代码中添加清单android:windowSoftInputMode ="adjustResize"参数.

编辑:正确的标志是:android:windowSoftInputMode ="adjustResize"

  • 试试`android:windowSoftInputMode ="adjustNothing"`.[此链接](http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode)应该会有所帮助. (9认同)
  • android:windowSoftInputMode ="adjustNothing"不是API公开的有效值 - 项目错误. (6认同)

Rav*_*avi 11

android下的所有属性中:在manifest中的windowSoftInputMode中唯一有效的是

机器人:windowSoftInputMode = "adjustNothing"

  • 不能相信,它没有证件;但这解决了我的问题!非常感谢。 (2认同)

pri*_*ero 5

在我的AndroidManifest文件中,我将以下代码添加到活动中:

android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)

历史

实际上,我尝试过AdjustResize和AdjustNothing,但它在我的最终没有用,所以我尝试了其他方法.我觉得这个答案很有用,希望它能解决你的问题!:)