gpt4 book ai didi

Java/Android : When I put a ScrollView - I get a soft keyboard. 布局不好

转载 作者:行者123 更新时间:2023-11-30 04:05:26 26 4
gpt4 key购买 nike

我的布局有问题。我想在我的 Activity 底部放置一个文本编辑器和一个按钮。然后我想要一个 TextView 组件来填充我的 Activity 布局上的所有可用空间。

我在 bigText 组件中有一个大文本,这就是我需要使用 ScrollView 的原因。

我有几个问题:

  1. 我不明白,为什么我在放置ScrollView组件时得到一个软键盘?但是没有 ScrollView 我就没有这个键盘!如果我关闭软键盘,像这样:

    getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );

    那我该如何使用我的 EditText 呢?

  2. 你能帮我布置一下吗?问题是:当我使用 ScrollView 时 - 它会填满所有手机的显示屏,我什至看到我的按钮和 EditText 应该放在 ScrollView 下方(我没有完全看到布局的底部)。我怎样才能解决这个问题?

那是我失败的布局尝试:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/bigText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />

</ScrollView>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search string: " />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="center_vertical|center_horizontal" >
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go >>" />

</LinearLayout>

</LinearLayout>

最佳答案

我不确定为什么添加 ScrollView 会弹出软键盘,但很容易补救。像这样以编程方式将其关闭:

  InputMethodManager manager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
IBinder binder = view.getApplicationWindowToken();
if (binder != null) {
manager.hideSoftInputFromWindow(binder, 0);
}

其中 View 可以是您的 ScrollView 或 TextView 或任何其他内容

关于Java/Android : When I put a ScrollView - I get a soft keyboard. 布局不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11750913/

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