当键盘打开时,用户界面向上移动。

10

我正在制作应用程序的用户界面(UI)。当我尝试在EditText中输入值时,键盘会将UI向上移动。 请帮助我,当键盘打开时,它不应该将UI向上移动。

<activity
        android:name=".AddProductsActivity"
        android:configChanges="orientation"
        android:hardwareAccelerated="false"
        android:windowSoftInputMode="adjustResize" />

可能是因为在该活动中使用了滚动视图。 - sharib ahmed
5个回答

12

它解决了我的问题。

谢谢大家。

<activity
    android:name=".AddProductsActivity"
    android:configChanges="orientation"
    android:hardwareAccelerated="false"
    android:windowSoftInputMode="adjustPan" />

1
  1. 在另一个RelativeLayout中使用RelativeLayout来显示顶部和底部栏,该布局覆盖整个屏幕。

对于顶部栏:

android:id="@+id/top"
android:layout_alignParentTop = "true"
android:layout_alignParentRight = "true"
android:layout_alignParentLeft = "true"
android:layout_width="wrap_content"
android:layout_height="<fix height like 50dp or as per requirement>"

for bottom bar :

android:id="@+id/bottom"
android:layout_alignParentBottom="true"

  1. 现在添加一个ScrollView,如下所示:

    android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/top" android:layout_above="@+id/bottom"

  2. 现在向此滚动视图添加一个子视图,可以是RelativeLayout或LineareLayout中的任何一个。我们需要这个子视图来仅包装其他我们想要添加到屏幕中间的子视图,现在我们想要看到的任何内容,只需将该视图作为此布局的子视图添加,例如EditText或您喜欢的任何内容。

现在当键盘弹出时,中间的滚动视图将向上滚动,这不会扭曲您的UI..

我希望这对您有所帮助,如果您仍然遇到问题,请回到我这里.. :)


0
请在清单文件中的活动标签中添加以下行:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

0

因为我在主活动中使用了TabActivity,然后在选项卡活动中使用了FragmentActivity,所以清单设置似乎没有起到作用。因此,我的解决方案是:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    setContentView(R.layout.activity_fragment);
    // Setup fragment
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new Fragment())
                .commit();
    }
}

在创建时显式调用setSoftInputMode(SOFT_INPUT_ADJUST_RESIZE)。希望这可以帮助一些人,如果manifest.xml没有帮助的话。

0
从清单文件中的标签中删除此行android:windowSoftInputMode="adjustResize",以使其适用于该活动。

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