【问题标题】:Edittext multiline in Constraints Layout and adjustpan scrollview not workable约束布局中的Edittext多行和adjustpan滚动视图不可用
【发布时间】:2016-12-04 04:47:32
【问题描述】:

我在fragment 中使用EditText,它在constraintsLayout 中,但是当我输入超过屏幕长度的更多行时,editText 不会向上移动。

我尝试将“windowSoftInputMode”设置为“adjustPan”和“adjustResize”,尝试将“isScrollContainer”设置为真假。

我尝试使用scrollview 并将我的EditText 设置为其子级。但都有同样的问题。

我的活动不是全屏。

下面的代码是我的manifest

<activity
        android:name=".MainActivity"
        android:screenOrientation="userPortrait"
        android:windowSoftInputMode="stateVisible|adjustPan">

以下代码是我的布局,它在约束布局中。

<EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textCapSentences|textAutoCorrect|textMultiLine|textWebEditText"
        android:ems="10"
        android:id="@+id/editText"
        android:imeOptions="actionSend"
        android:scrollHorizontally="false"
        android:saveEnabled="true"
        android:scrollbars="vertical"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="32dp"
        app:layout_constraintHorizontal_bias="0.0"
        android:isScrollContainer="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:hint="@string/writeYourPostHere"/>

这是我的片段在输入任何内容之前的外观。

这是我的片段的外观,当我用“行号”键入 20 行单词“testing”时,它没有向上移动,并且其余的单词(Testing 18,Testing 19,Testing 20)被隐藏了,即使我我仍在输入“测试 20”字样。我希望它向上移动并显示我输入的最后一个字。

我已经阅读了以下链接中的答案,但它们看起来都一样,无法解决我的问题。

EditText, adjustPan, ScrollView issue in android

adjustPan not preventing keyboard from covering EditText

Forcing adjustPan in activity containing ScrollView

Android EditText Multiline with SoftInputMode adjustPan

How to avoid soft keyboard pushing up my layout?

Soft keyboard hides parts of fullscreen webview

Android adjustPan is being ignored

【问题讨论】:

    标签: android android-fragments android-edittext


    【解决方案1】:

    我通过以下方法找到了答案。

    1) 将scrollview 放在constraintslayout 之外,以前我只是使用scrollviewedittext 作为唯一的孩子。

    <ScrollView>
        <ConstraintsLayout>
            <EditText>
            </>
        </>
    </>
    

    2) 对于editText,设置为

    android:imeOptions="flagNoExtractUi"
    

    3) 最后,我将这段代码放在onCreateView 中,用于fragment

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    

    【讨论】:

    • 确实可以使用 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);实现对edittext的平移。您可以将约束排除在滚动视图之外。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    相关资源
    最近更新 更多