簡體   English   中英

當出現軟鍵盤時,僅將底部向上推

[英]Push only the bottom part up when Soft keyboard appears

我唯一嘗試做的是在頂部有一個editText,然后是ImageView。 現在,在最底行將有一些按鈕(例如表情符號),並且只要出現,該底部僅由軟鍵盤向上推。

我通過附加Facebook的這種布局使其更加清晰。 所需的輸出

我經歷了所有這些SO問題,也嘗試了答案,但是沒有運氣。 可能是我做錯了。

Android:使用屏幕上的軟鍵盤僅調整部分視圖的大小

Android:如何防止軟鍵盤將視圖向上推?

android:如何防止顯示虛擬鍵盤時調整窗口大小

我的XML代碼

<ScrollView
    android:id="@+id/scrollOnPost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="false"
    android:fillViewport="true"
    android:layout_below="@+id/header_layout">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="4"
    android:layout_gravity="bottom"
    android:gravity="bottom">
 <EditText
            android:id="@+id/ed_post"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
<ImageView
        android:id="@+id/img_posted_list_row"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.7"
        android:adjustViewBounds="true"
        android:src="@mipmap/ic_launcher"
        android:scaleType="fitCenter"
        android:background="@color/red"/>

</LinearLayout>
</ScrollView>

<ImageButton
    android:id="@+id/imgBtn_Emoji"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:src="@drawable/smile_face"
    android:background="@drawable/button_pressed_white"
    />

我得到的所有東西都是,我的軟鍵盤總是將整個布局推到頂部,而不僅僅是底部的表情符號。 謝謝。

杜德它的工作清單:

<activity android:name=".TestActivity"
        android:windowSoftInputMode="adjustResize"/>

xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scrollOnPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:fillViewport="true"
android:layout_below="@+id/header_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="4"
    android:layout_gravity="bottom"
    android:gravity="bottom">
    <EditText
        android:id="@+id/ed_post"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <ImageView
        android:id="@+id/img_posted_list_row"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.7"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:background="@color/colorPrimary"/>
    <ImageButton
        android:id="@+id/imgBtn_Emoji"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:src="@mipmap/call"
        />
</LinearLayout>

我想您只希望在可見鍵盤時將editText推入(如果我錯了,請糾正我),因為我有一個主意,我不知道它是否會起作用,如果您發現它符合邏輯就可以嘗試一下

想法是首先檢查鍵盤是否可見,其次檢查可見的高度,並以編程方式為您的布局提供一個marginBottom,它等於鍵盤的高度(使用layoutParams)。

檢查此鏈接以實現上述想法:

如何在Android中捕獲“虛擬鍵盤顯示/隱藏”事件?

Android中有什么方法可以獲取設備虛擬鍵盤的高度

如何在不在XML中的代碼中設置RelativeLayout布局參數

在單擊編輯文本之前

單擊編輯文本后

暫無
暫無

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

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