gpt4 book ai didi

android - 显示键盘时向上推送内容,但某些 View 除外

转载 作者:IT老高 更新时间:2023-10-28 23:32:02 24 4
gpt4 key购买 nike

我的布局在底部包含 5 个 EditText 和一个 Button 和一个 TextView。现在,当我按下 EditText 时,键盘将显示并且 all 我的 View 向上推。

现在我不想将我的 TextViewButton 推到键盘上方,只想全部推上 ScrollView 内的 EditText 到键盘上方。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0"
>

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

<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 1"

/>

<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 2"
/>

<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 3"
/>

<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 4"
/>

<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EditText 5"
android:inputType="textNoSuggestions"
/>

</LinearLayout>

</ScrollView>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="I don't want to push this TextView and Button to above keyboard when keyboard is shown. Just obly want to push the ScrollView that contain all EditText"
/>
</LinearLayout>

enter image description here

我有个想法是。当键盘显示和隐藏时我会监听。当键盘显示时我将设置 ScrollView 的底部边距 = 键盘高度,当键盘隐藏时我将设置此边距 = 0。
有什么方法更容易处理我的案子吗?任何帮助或建议将不胜感激。

更新
如果我使用 windowSoftInputMode=adjustPan => 并非所有 EditText 都被推到键盘上方
如果我使用 windowSoftInputMode=adjustResize => Button, TextView 并且所有 EditText 都被推到键盘上方

最佳答案

不起作用 - 没有可靠的 API 来检测键盘何时显示。您会在此站点上看到“解决方案”,但它们有误报和误报。但似乎对您来说最好的方法是将 softInputMode 设置为 adjustPan。这将使操作系统以使光标在键盘上方可见所需的最小量滚动整个屏幕。 (整个应用程序在键盘上方是由于模式adjustResize)。

关于android - 显示键盘时向上推送内容,但某些 View 除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41582691/

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