簡體   English   中英

將嵌套滾動視圖滾動到 textView 的底部

[英]Scroll nestedscrollview to bottom of textView

我的活動中有一些editText ,因此將它們放入nestedScrollView ,並且我的活動具有adjustResize屬性。 我在每個editText的底部放了一個textView來顯示exitText輸入錯誤。 但他們的visibility已經Gone 當軟鍵盤打開時,第一個exitText沒有問題,當我單擊軟噴射板的Next按鈕時, nestedScrollView滾動到下一個editText的底部,如果用戶向我的editText寫入錯誤的輸入,則textView的它們將是可見的,並向用戶顯示輸入錯誤。

但問題是

他們在他們的editText 如何將textView滾動到nestedScrollView的底部?

您可以只使用TextInputEditTextTextInputLayout而不是EditTextTextView

滾動行為將由 Android 系統管理,並且結果應該正確。

此外,它將簡化您的代碼:

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        app:errorEnabled="true">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/text_input_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Hint"/>

    </com.google.android.material.textfield.TextInputLayout>

您可以設置和刪除錯誤:

Java

text_input_layout.setError("Error message");
text_input_layout.setError(null);

Kotlin

text_input_layout.error = "Error message"
text_input_layout.error = null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM