当软键盘打开android时,将标题置于顶部

时间:2016-04-25 12:02:49

标签: java android android-layout android-fragments

我有一个布局,我需要在打开softKeyBoard时不应隐藏顶部标题。我在这里使用Fragment。我正在使用recylerView。 当我打开软键盘时,顶部标题向上滚动。我需要那个标题留在那里和Recyclerview滚动。

下面是我的xml。

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rel_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bggradient">

        <RelativeLayout
            android:id="@+id/rel_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:background="@drawable/drawable_below_line">

            <ImageView
                android:id="@+id/iv_menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/txtSettingHeader"
                android:layout_alignTop="@+id/txtSettingHeader"
                android:layout_centerVertical="true"
                android:background="@drawable/button_selector"
                android:onClick="onClickEvent"
                android:padding="10dp"
                android:src="@mipmap/ic_back" />

            <TextView
                android:id="@+id/txtUserName"
                style="@style/FragHeader"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true" />

            <ImageView
                android:id="@+id/iv_userImage"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/txtUserName"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/txtUserName"
                android:layout_centerVertical="true"
                android:onClick="onViewClick"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:src="@mipmap/ic_male" />


        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/lin_comment"
            android:layout_below="@+id/rel_header"
            android:gravity="top"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/RecyelerViewChat"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="visible">

            </android.support.v7.widget.RecyclerView>

            <TextView
                android:id="@+id/tv_txtNoRecords"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:minHeight="100dp"
                android:text="@string/txtNoChat"
                android:textColor="@android:color/white"
                android:visibility="gone" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/lin_comment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#70FFFFFF"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="5dp">

            <LinearLayout
                android:id="@+id/linEditComment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:focusableInTouchMode="true"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/iv_imgToggleKeyboardEmoji"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:clickable="true"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:src="@mipmap/ic_emoji" />

                <com.lawo.emojicon.EmojiconEditText
                    android:id="@+id/et_edtChat"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/drawable_black_border"
                    android:hint="@string/hintTypeMessage"
                    android:inputType="textNoSuggestions|textMultiLine"
                    android:maxLength="500"
                    android:maxLines="3"
                    android:padding="10dp"
                    android:textColor="@android:color/black"
                    android:textColorHint="@android:color/darker_gray" />
            </LinearLayout>

            <ImageView
                android:id="@+id/iv_imgSend"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="onClickEvent"
                android:padding="10dp"
                android:src="@mipmap/ic_sent" />

        </LinearLayout>




    </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

将以下内容添加到您的&#34;活动&#34; AndroidManifest.xml中的标记:

android:windowSoftInputMode="adjustResize"

参考:Specify How Your UI Should Respond