久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

顯示鍵盤時向上推送內容,但某些視圖除外

Push up content except some view when keyboard shown(顯示鍵盤時向上推送內容,但某些視圖除外)
本文介紹了顯示鍵盤時向上推送內容,但某些視圖除外的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的布局在底部包含 5 個 EditText 和一個 Button 和一個 TextView.現在,當我按下 EditText 時,鍵盤將顯示并且 all 我的 View 向上推.

I have a layout that contains 5 EditText and a Button and a TextView at bottom. Now when I press an EditText then the keyboard will shown and all my View is push up.

現在我不想將我的 TextViewButton 推到鍵盤上方,只想全部推上 ScrollView 內的 EditText 到鍵盤上方.

Now I don't want to push my TextView and Button to above keyboard, just only want to push up all EditText inside ScrollView to above keyboard.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 1"

                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 2"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 3"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 4"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 5"
                android:inputType="textNoSuggestions"
                />

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:text="I don't want to push this TextView and Button to above keyboard when keyboard is shown. Just obly want to push the ScrollView that contain all EditText"
        />
</LinearLayout>

我有個想法是.當鍵盤顯示和隱藏時我會監聽.當鍵盤顯示時,我將設置 ScrollView 的底部邊距 = 鍵盤高度,當鍵盤隱藏時,我將設置此邊距 = 0.
有什么方法更容易處理我的案子嗎?任何幫助或建議將不勝感激.

I have an idea is. When I will listener when keyboard show and hide. When keyboard show I will set the bottom margin of ScrollView = keyboard height, when keyboard hide I will set this margin = 0.
Is there any way easier to handle my case? Any help or suggestion would be great appreciated.

更新
如果我使用 windowSoftInputMode=adjustPan => 并非所有 EditText 都被推到鍵盤上方
如果我使用 windowSoftInputMode=adjustResize => Button, TextView 并且所有 EditText 都被推到鍵盤上方

UPDATE
If I use windowSoftInputMode=adjustPan => not all EditText is push up to above keyboard
If I use windowSoftInputMode=adjustResize => Button, TextView and all EditText is push up to above keyboard

推薦答案

有了 WindowInsetsCompat 的新功能,可以幫助輕松檢測鍵盤可見性(我在這里按照答案 https://stackoverflow.com/a/63517673/5381331).
而不是像以前那樣使用 windowSoftInputMode=adjustPan 來降低復雜性,現在我可以通過將 windowSoftInputMode=adjustResizeWindowInsetsCompat

With the new feature of WindowInsetsCompat which help detecting keyboard visibility easily (I follow answer here https://stackoverflow.com/a/63517673/5381331).
Instead of using windowSoftInputMode=adjustPan for less complex like before, now I can solve this problem by combine windowSoftInputMode=adjustResize with WindowInsetsCompat

ViewCompat.setOnApplyWindowInsetsListener(root) { v, insets ->
    val isKeyboardVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
    
    if (isKeyboardVisible) {
        // Hide some view when keyboard visible
    } else {
        // Show it again here
    }
}

AndroidManifest

AndroidManifest

<activity android:name=".activity_name"
        android:windowSoftInputMode="adjustResize"> // all content will push to above keyboard then we able to scroll to see whole content
   
</activity>

這篇關于顯示鍵盤時向上推送內容,但某些視圖除外的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久精品国产99国产精品 | 久热精品视频 | 国产一区在线免费 | 免费看a | 美女国内精品自产拍在线播放 | 亚洲男人的天堂网站 | 久久午夜视频 | 日韩一区中文字幕 | 国产一区二区三区久久久久久久久 | 视频一区二区中文字幕 | 国产综合久久久久久鬼色 | 久久成 | 在线观看中文字幕av | 午夜电影网站 | 国产精品视频网 | 综合色在线 | 精品国产青草久久久久96 | 亚洲一区二区三区在线观看免费 | 五月激情婷婷六月 | 天天拍天天操 | 午夜影院网站 | 国产成人精品在线播放 | 欧美视频在线播放 | 99热.com | 精品乱人伦一区二区三区 | 99国产精品99久久久久久粉嫩 | 日本免费一区二区三区视频 | 中文精品视频 | 日韩一区二区三区视频在线播放 | 成人毛片一区二区三区 | 国产精品99久久久久久久久 | 香蕉大人久久国产成人av | 91精品久久久久 | 精品国产欧美一区二区三区成人 | 午夜影院 | 一区视频在线播放 | 亚洲精品欧美 | 在线免费观看a级片 | 欧美二区在线 | 精品免费看 | 日本在线视频一区二区 |