【发布时间】:2017-12-07 19:16:40
【问题描述】:
看来adjustPan 实际上是在我的EditText 的基线上平移,而不是视图的实际边缘。
我一直在寻找解决此问题的方法,但我一直找不到任何东西。
活动代码(kotlin):
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
window.setSoftInputMode(SOFT_INPUT_ADJUST_PAN)
}
布局xml:
<android.support.constraint.ConstraintLayout
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="match_parent"
tools:context="com.foo.testbed.MainActivity">
<EditText
android:id="@+id/myEditText"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="8dp"
android:background="@drawable/rounded_edit_text"
android:hint="Message"
android:paddingStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/myButton"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="Send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/myEditText" />
我尝试了以下问题的解决方案,但无济于事:
【问题讨论】:
-
AdjustPan 只保证光标在视图中,而不是整个编辑文本。没有办法解决这个问题,它按预期工作,也没有办法改变它的工作方式。
-
@nukeforum 发现了什么?
-
@iCantC 可以找到更常见的答案之一davidwparker.com/2011/08/25/… 或stackoverflow.com/a/3521781。本质上,将您的布局包装成可滚动允许布局稍微调整以正确显示。
标签: android