gpt4 book ai didi

Android adjustResize 布局用软键盘调整大小

转载 作者:行者123 更新时间:2023-11-29 22:20:35 24 4
gpt4 key购买 nike

我正在努力获得一个小的 EditText 以及与屏幕底部软件键盘底部对齐的两个按钮。基本上我的问题是每次我打开我的 Activity (标记为 adjustResize | stateAlwaysVisible)和布局时:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_alignParentBottom="true">

<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/soft_input_edit_placeholder">
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:weightSum="2" android:id="@+id/soft_input_layout_buttons">
<Button android:layout_width="0dp" android:text="xxx Submit xxx" android:layout_height="wrap_content" android:id="@+id/soft_input_button_submit" android:layout_weight="1"></Button>
<Button android:layout_width="0dp" android:text="xxx Cancel xxx" android:layout_height="wrap_content" android:id="@+id/soft_input_button_cancel" android:layout_weight="1"></Button>
</LinearLayout>
</LinearLayout>

键盘向上滑动,它会调整 Activity 的大小,以便只有编辑文本可见,当我隐藏它时(至少键盘有一个按钮可以让我隐藏它),布局保持在原位,也就是说,它永远不会滑回原位,留下一半的屏幕未被覆盖。

我读到在大多数情况下对齐是通过在布局中引入一些可扩展的控件来实现的,但我真的不希望在那里有任何形式的 ListView;我试过使用 RelativeLayout,还是不行。将一个嵌入另一个 - 仍然没有运气。如果您有任何建议,我将非常感谢,我的想法已经用完了..

谢谢!

最佳答案

问题全部出在选定的主题上。我的 Activity 在 list 中应用了全屏主题(我不知道它会以这种方式影响 View );将其更改为非全屏解决了我的问题(尽管它不能只是任何其他主题)

我通过将 Activity 主题设置为 Theme.Translucent 并将布局主题设置为 Theme (根本没有主题)来实现我的目标;将 @android:drawable/bottom_bar 应用到主 LinearLayout 并最终将主布局的引力设置为 bottom 给了我想要的结果。

关于Android adjustResize 布局用软键盘调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7332991/

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