首页 > 解决方案 > 如何根据软键盘调整布局

问题描述

当软键盘出现时,我有一个评论部分的对话框布局整个布局上升我不希望我只希望编辑文本随着键盘上下移动,第二件事是当用户输入多行评论时编辑文字隐藏在软键盘后面。

假设当只有一个评论并且有人正在输入评论时,第一个评论将上升并且对用户不可见。

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

标签: android

解决方案


推荐阅读