gpt4 book ai didi

android - 尽管使用了 adjustResize,但键盘仍显示在表单上

转载 作者:行者123 更新时间:2023-11-29 01:08:20 25 4
gpt4 key购买 nike

当键盘显示在我的应用程序上时,我想向上移动我的布局。我在 Activity 中使用了 adjustResize、adjustPan 和它们两者,但它们都不起作用,它仍然在窗体上显示键盘并且不会移动上面的布局。

这是我的布局:

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

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

............... my views

</LinearLayout>
</ScrollView>
</RelativeLayout>

我怎样才能让它发挥作用?

最佳答案

这样试试

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > dpToPx(getApplicationContext(), 200)) { // if more than 200 dp, it's probably a keyboard...
// ... do something here
}
}
});


public static float dpToPx(Context context, float valueInDp) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueInDp, metrics);
}

然后将其添加到您的 xml 中
android:id="@+id/activityRoot"

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:id="@+id/activityRoot"**>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

............... my views

</LinearLayout>
</ScrollView>
</RelativeLayout>

关于android - 尽管使用了 adjustResize,但键盘仍显示在表单上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45341966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com