作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的布局有问题。我想在我的 Activity 底部放置一个文本编辑器和一个按钮。然后我想要一个 TextView 组件来填充我的 Activity 布局上的所有可用空间。
我在 bigText 组件中有一个大文本,这就是我需要使用 ScrollView 的原因。
我有几个问题:
我不明白,为什么我在放置ScrollView组件时得到一个软键盘?但是没有 ScrollView 我就没有这个键盘!如果我关闭软键盘,像这样:
getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );
那我该如何使用我的 EditText 呢?
你能帮我布置一下吗?问题是:当我使用 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/
我是一名优秀的程序员,十分优秀!