简体   繁体   English

当出现软键盘时,仅将底部向上推

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

The only thing I am trying do that there will be an editText at the top and after that there will be an ImageView. 我唯一尝试做的是在顶部有一个editText,然后是ImageView。 Now at the bottom line there will be some buttons (ex. emojis) and this bottom part will only be pushed up by the soft keyboard whenever it will appear. 现在,在最底行将有一些按钮(例如表情符号),并且只要出现,该底部仅由软键盘向上推。

I am making it more clear by attaching this layout of Facebook. 我通过附加Facebook的这种布局使其更加清晰。 required output 所需的输出

I have gone through all these SO questions and also tried their answers but no luck. 我经历了所有这些SO问题,也尝试了答案,但是没有运气。 May be I am doing something wrong. 可能是我做错了。

Android: Resize only parts of view with soft keyboard on screen Android:使用屏幕上的软键盘仅调整部分视图的大小

Android: How do I prevent the soft keyboard from pushing my view up? Android:如何防止软键盘将视图向上推?

android : How to prevent resizing the window when displaying the virtual keyboard android:如何防止显示虚拟键盘时调整窗口大小

My XML code 我的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"
    />

All I getting that my soft keyboard always pushing the whole layout up not just the emoji at the bottom. 我得到的所有东西都是,我的软键盘总是将整个布局推到顶部,而不仅仅是底部的表情符号。 Thanks. 谢谢。

Dude it worked manifest : 杜德它的工作清单:

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

xml : 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>

I guess you want only the editText to push up when keyboard is visible(Correct me if i am wrong) for that i have got an idea i don't know if it will work or not you can try it out if you find it logical 我想您只希望在可见键盘时将editText推入(如果我错了,请纠正我),因为我有一个主意,我不知道它是否会起作用,如果您发现它符合逻辑就可以尝试一下

Idea is to first check if keyboard is visible or not and secondly if visible get its height and programatically give your layout a marginBottom which will be equal to the height of keyboard(using layoutParams). 想法是首先检查键盘是否可见,其次检查可见的高度,并以编程方式为您的布局提供一个marginBottom,它等于键盘的高度(使用layoutParams)。

check this links for implementing above idea : 检查此链接以实现上述想法:

How to capture the "virtual keyboard show/hide" event in Android? 如何在Android中捕获“虚拟键盘显示/隐藏”事件?

Is there any way in android to get the height of virtual keyboard of device Android中有什么方法可以获取设备虚拟键盘的高度

How to set RelativeLayout layout params in code not in xml 如何在不在XML中的代码中设置RelativeLayout布局参数

在单击编辑文本之前

单击编辑文本后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM