【问题标题】:Android: How to avoid layout being pushed when keyboard invokedAndroid:如何避免在调用键盘时推送布局
【发布时间】:2011-10-24 15:28:05
【问题描述】:

我的布局如下

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

当通过单击编辑文本调用软键盘时,整个布局被推送。我可以保持标题上的按钮固定并让图像视图被推送吗?因为按钮会像导航栏一样,所以即使布局被向上推,它也应该在那里。

之前

之后

【问题讨论】:

    标签: android xml layout keyboard android-edittext


    【解决方案1】:

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

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

    【讨论】:

    • android:windowSoftInputMode="adjustPan" 没有帮助:(
    • 试试android:windowSoftInputMode="adjustNothing"This link 应该会有所帮助。
    • 请尝试:android:windowSoftInputMode="adjustResize",我弄错了标签。这应该工作:)
    • android:windowSoftInputMode="adjustNothing" 不是 API 公开的有效值 - 项目因此出错。
    • 很高兴编辑您的真实答案,这样我们就不必查看 cmets 来获得正确的答案。
    【解决方案2】:

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

    android:windowSoftInputMode="adjustPan"
    

    历史

    实际上,我尝试了 AdjustResize 和 AdjustNothing 但它对我来说不起作用,所以我尝试了其他方法。我发现这个答案很有用,希望它也能解决你的问题! :)

    【讨论】:

      【解决方案3】:

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

      android:windowSoftInputMode="adjustNothing"

      【讨论】:

      • 不敢相信,它没有记录;但这解决了我的问题!非常感谢。
      • 这也解决了我的问题!谢谢,我的布局不是一个可滚动的视图,所以在片段替换时它自然会用软键盘向上推动它。
      • 有谁知道旧的安卓版本是否有关于“adjustNothing”值的问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 2013-05-23
      相关资源
      最近更新 更多