Yul*_*lia 7 android android-softkeyboard android-edittext
问题是android键盘在打开时将textview隐藏在edittext下(不是edittext本身!)。
这是我的布局示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="wrap_content"
tools:context=".MainActivity">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/big_image"
android:layout_width="200dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:src="@drawable/ic_launcher_foreground"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/comment_input_layout"
android:text="0/250"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
下面的图片可以清楚地说明:
我在stackoverflow上发现了几个类似的问题,没有一个有解决方案:(请帮我解决这个问题!请确保,我使用了所有考虑android:windowSoftInputMode="adjustPan"
或android:windowSoftInputMode="adjustResize"
或android:focusableInTouchMode="true"
或的建议android:fitsSystemWindows="true"
或将这个textview与edittext布局分开,将framelayout作为根,
但问题有点复杂。
另一个重要的事情是,edittext 下面的这个文本应该
当文本在另一行上时保持在键盘上方
当 edittext 向上滚动时消失(因为它是 edittext 的一部分)。
小智 1
我遇到了同样的问题。我已经向 Material记录了与此相关的票证。感谢我出色的同事的建议,我应用的“黑客”是这样的:每当渲染布局并且我单击具有计数器的字段(这是我的布局上的最后一个字段)时,以编程方式将其滚动到底部,所以键盘不再隐藏计数器。
以下是我的程序的不同代码片段,您可以参考:
override fun onFocusChange(p0: View?, isOnFocus: Boolean) {
if (isOnFocus.not() && getDescription().isEmpty()) {
tnDescriptionLayout.error = resources.getString(R.string.description_error_message)
tnDescriptionLayout.isErrorEnabled = true
} else {
tnDescriptionLayout.isErrorEnabled = false
llayout.postDelayed(object : Runnable {
override fun run() {
var v =
tnDescriptionLayout.findViewById<AppCompatTextView>(R.id.textinput_counter)
nestedScrollView.smoothScrollBy(0,v.height)
}
}, CoreConstants.MINIMUM_VIEW_LOAD_DURATION)
}
tvDescription.setText(getDescription())
lateinit var nestedScrollView: NestedScrollView
fun change(nestedScrollView: NestedScrollView){
this.nestedScrollView=nestedScrollView
}
paymentOrderContent.change(nestedScrollView = parentView.nestedScrollViewParent)
Run Code Online (Sandbox Code Playgroud)
我希望这对您有帮助!
| 归档时间: |
|
| 查看次数: |
700 次 |
| 最近记录: |