android - 如何根据软键盘调整布局
问题描述
当软键盘出现时,我有一个评论部分的对话框布局整个布局上升我不希望我只希望编辑文本随着键盘上下移动,第二件事是当用户输入多行评论时编辑文字隐藏在软键盘后面。
假设当只有一个评论并且有人正在输入评论时,第一个评论将上升并且对用户不可见。
我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_13sdp"
android:layout_marginLeft="@dimen/_5sdp"
android:layout_marginRight="@dimen/_5sdp"
android:background="@color/backgroud_offwhite"
android:id="@+id/rl">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroud_offwhite"
android:layout_above="@+id/vw">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/rv"
android:layout_marginBottom="@dimen/_10sdp">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/Nocomments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="@color/hint_color"
android:text="No comments yet"
android:layout_centerInParent="true"
android:textSize="@dimen/_16sdp"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/loader"
android:layout_width="@dimen/_30sdp"
android:layout_height="@dimen/_30sdp"
android:layout_centerInParent="true"
android:visibility="gone"
android:indeterminateDrawable="@drawable/progress_bar" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/vw">
<include
android:id="@+id/loadItemsLayout_recyclerView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/commnt_bottom_layout"
android:visibility="gone" />
</RelativeLayout>
<View
android:id="@+id/vw"
android:layout_above="@+id/ll_send_message"
android:layout_width="match_parent"
android:layout_height="@dimen/_1sdp"
android:background="@color/appColor" ></View>
<LinearLayout
android:id="@+id/ll_send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@color/backgroud_offwhite">
<EditText
android:id="@+id/editMessage"
android:layout_width="0dp"
android:hint="Write a comment..."
android:layout_height="wrap_content"
android:maxHeight="@dimen/_50sdp"
android:scrollbars="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:textColorHint="@color/hint_color"
android:inputType="textMultiLine|textCapSentences"
android:backgroundTint="@android:color/transparent"
android:scrollHorizontally="false"
android:textCursorDrawable="@color/appColor"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<RelativeLayout
android:id="@+id/buttonSend"
android:layout_width="@dimen/_50sdp"
android:layout_height="match_parent"
android:gravity="top"
android:layout_marginRight="@dimen/_6sdp"
>
<ImageView
android:id="@+id/sendimg"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:layout_centerInParent="true"
android:background="@drawable/ic_send_button" />
<ProgressBar
android:id="@+id/loaderimg"
android:layout_centerInParent="true"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:indeterminateDrawable="@drawable/progress_bar"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
解决方案
推荐阅读
- python - 使用 Pip 安装模块时出错
- python - 在 OpenCV Python 中使用鼠标单击在较大的图像上拖动、调整大小和旋转图像
- excel - MDX 计算不适用于 excel 中的小计
- arrays - 扩展集合:数组和集合,但不是字典
- tcl - 在 Tcl 脚本行中,是否可以编写 2 个或更多命令?
- json - pandas json 使用特定的 json 属性规范化键错误
- javascript - “AppComponent”类型上不存在属性“alertService”和“选项”
- wpf - Powershell GUI - 选择后将变量添加到单选按钮
- java - 隐藏的J对话框
- c# - 如何使用 .net 核心应用程序中的中间件操作当前令牌的 ClaimsIdentity?