繁体   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