gpt4 book ai didi

android - 为什么我的布局不能向上移动 "adjustPan"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:50:48 29 4
gpt4 key购买 nike

我在我的应用程序中使用 adjustPan 时遇到了一些问题,因为它没有按预期工作。其他一些用户也遇到了这个问题,所以我认为分享这个问题很重要 (Layout doesn't move up enough when clicking EditText)。

注意:我使用的是 Android Studio 并且我使用的是“即时应用”,因此文件的位置会有些不同。

当我在布局中使用 adjustPan 时,我的 Activity 没有向上移动到 EditText 出现在软键盘上方的位置(有关详细信息,请参见图片)。无论您在 Manifest 文件还是 Java 文件中使用它,仍然会出现相同的结果。

不仅如此,最奇怪的部分是状态栏变得透明并且应该位于通知图标后面的深蓝色条向下一点(有关详细信息,请参见图片)。

Screenshot of issue

我曾多次尝试解决这个问题,例如使用 adjustResizesetOnTouchListener,但我收到的这两个答案都没有解决这个问题。

我仍然无法弄清楚这个问题的原因,所以关于如何发现这个问题发生的原因的任何答案或评论也很好。

这是我的一些代码:

list 文件:

<activity
android:name=".Input_Activity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />

Java 文件:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;

public class Input_Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input__activity);

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
}

XML 文件:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".Input_Activity">

<EditText
android:layout_width="214dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:inputType="number|numberDecimal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.585"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.725" />

我们将不胜感激所有反馈。

最佳答案

在类级别创建一个对象,如 InputMethodManager methodManager。
将这些行添加到您的 onCreate() 方法中,

methodManager = (InputMethodManager) this.getSystemService(this.INPUT_METHOD_SERVICE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

在你的 onClick() 方法中,显示键盘,

methodManager.toggleSoftInputFromWindow(
your_view_name.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);

如果这个词 getApplicationWindowToken 抛出一个错误,然后将其替换为 getWindowToken
希望对您有所帮助。

关于android - 为什么我的布局不能向上移动 "adjustPan"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54545557/

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