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

时间:2011-08-11 04:07:24

标签: android xml layout keyboard 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>

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

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:11)

在此阅读文章:http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
您应该在您的活动代码中添加manifest android:windowSoftInputMode =“adjustResize”参数。

EDITED: 正确的标志是:android:windowSoftInputMode =“adjustResize”

答案 1 :(得分:9)

在清单中 android:windowSoftInputMode 下的所有属性中,唯一可行的是

<强>机器人:windowSoftInputMode = “adjustNothing”

答案 2 :(得分:5)

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

android:windowSoftInputMode="adjustPan"

<强>记录

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