【问题标题】:Push only the bottom part up when Soft keyboard appears出现软键盘时仅将底部向上推
【发布时间】:2017-02-16 11:17:01
【问题描述】:

我唯一想做的就是顶部有一个editText,之后会有一个ImageView。 现在在底线会有一些按钮(例如表情符号),并且这个底部只会在出现时被软键盘向上推。

我通过附上 Facebook 的这个布局更清楚地说明了这一点。 required output

我已经解决了所有这些 SO 问题,也尝试了他们的答案,但没有运气。可能是我做错了什么。

Android: Resize only parts of view with soft keyboard on screen

Android: How do I prevent the soft keyboard from pushing my view up?

android : How to prevent resizing the window when displaying the virtual keyboard

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

我发现我的软键盘总是将整个布局向上推,而不仅仅是底部的表情符号。谢谢。

【问题讨论】:

  • 查看此链接可能对您有所帮助:stackoverflow.com/questions/17410499/…
  • 感谢库纳尔的链接。我已经在清单中同时尝试了 "adjustResize" 、 "adjustPan" 和两者,但结果不是我需要的。但问题与我的问题完全相同。再次感谢。
  • @ Md. Asaduzzaman Noor 我尝试在我的代码中添加您的布局,然后我可以找到什么解决方案
  • 好的,只需将我的整个代码包装到一个 RelativeLayout 中,然后将您想要测试的任何键盘模式放入清单中。
  • 你检查了吗?如果对您有帮助,请将其标记为答案并点赞

标签: android layout android-edittext scrollview android-softkeyboard


【解决方案1】:

老兄,它成功了 清单:

<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,该marginBottom将等于键盘的高度(使用layoutParams)。

检查此链接以实现上述想法:

How to capture the "virtual keyboard show/hide" event in Android?

Is there any way in android to get the height of virtual keyboard of device

How to set RelativeLayout layout params in code not in xml

【讨论】:

  • 感谢您尝试帮助@Kunal,但它不起作用,请查看附件图片并尝试清楚地了解我的要求。
  • 感谢 Kunal 的建议,但我很久以前就有了这个想法,并且也尝试过。但它并不适用于所有类型的设备,当然这不是最佳实践。我只是想知道facebook这样做的同样方式。就是这样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
  • 2019-10-02
  • 2015-12-07
  • 1970-01-01
相关资源
最近更新 更多