【问题标题】:adjustPan cuts off bottom of EditTextadjustPan 切断 EditText 的底部
【发布时间】: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


【解决方案1】:

解决办法是设置一个top&bot paddings

我的editText示例:

<AutoCompleteTextView
                android:id="@+id/editText_new_password"
                android:layout_width="match_parent"
                android:layout_height="@dimen/btn_editbox_height"
                android:background="@drawable/edit_text_style"
                android:gravity="center_vertical"
                android:paddingEnd="@dimen/login_edit_box_pass_padding_right"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                android:paddingStart="@dimen/edit_box_padding"
                android:textSize="14sp" />

填充 12:

和裸填充:

【讨论】:

  • 这不是一个完美的解决方案,但它确实解决了我的问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-05
  • 1970-01-01
  • 2014-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多