Android键盘向上移动我的整个屏幕

时间:2016-12-13 10:20:06

标签: android android-layout android-softkeyboard

Android当我点击布局底部的编辑文本时,整个屏幕会在全屏活动中向上移动

When key board is hidden

当键盘打开时,顶部的布局用于在屏幕上移动,但我想要显示的布局

When keyboard is up the layout at top used to move

这是我的布局代码

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout_chat_container"
    style="@style/MatchParent"
    tools:ignore="RtlHardcoded">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ll_action"
        android:orientation="vertical">
        <RelativeLayout
            android:id="@+id/navbar"
            android:layout_width="fill_parent"
            android:layout_height="76dp"
            android:visibility="visible"
            >
            <LinearLayout
                android:id="@+id/ll_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:background="@drawable/statusbar"></LinearLayout>
            <View
                android:id="@+id/line"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#ffff01"
                android:layout_below="@+id/ll_view"/>

            <LinearLayout
                android:id="@+id/ll_back_button"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:visibility="visible"
                android:layout_marginTop="25dp"
                android:orientation="vertical">

            </LinearLayout>
            <RelativeLayout
                android:layout_width="50dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:layout_below="@+id/line"
                android:onClick="onStartNewChatClick"
                android:layout_height="match_parent">
                <ImageView
                    android:id="@+id/fab_dialogs_new_chat"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:background="@drawable/qb_info"
                    android:visibility="visible"
                    android:layout_gravity="center"
                    android:layout_centerInParent="true"


                    />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="50dp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="5dp"
                android:layout_below="@+id/line"
                android:onClick="onStartNewChatBack"
                android:layout_height="match_parent">
                <ImageView
                    android:id="@+id/img_back"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:background="@drawable/qb_back"
                    android:visibility="visible"
                    android:layout_gravity="center"
                    android:layout_centerInParent="true"


                    />
            </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:layout_below="@+id/line"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/txtv_myuserloginname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:text="USER"
                android:layout_marginTop="10dp"
                android:layout_centerHorizontal="true"
                android:textColor="#222222"
                android:gravity="center"
                android:textSize="15dp"
                />
        </RelativeLayout>
        </RelativeLayout>
        <View
            android:id="@+id/view"
            android:layout_below="@+id/navbar"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="#ffff01"/>
    </LinearLayout>

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
        android:id="@+id/list_chat_messages"
        style="@style/ListViewWithoutDividerStyle"
        android:layout_above="@+id/layout_attachment_preview_container"
        android:layout_below="@+id/ll_action"
        android:listSelector="@android:color/transparent"
        android:stackFromBottom="true" />

    <ProgressBar
        android:id="@+id/progress_chat"
        style="@style/CenterProgressBarStyle" />

    <LinearLayout
        android:id="@+id/layout_attachment_preview_container"
        style="@style/MatchWidth"
        android:layout_height="96dp"
        android:layout_above="@+id/layout_chat_send_container"
        android:background="?attr/colorPrimary"
        android:orientation="vertical"
        android:visibility="gone">

        <View
            android:id="@+id/divider_chat_attachments"
            style="@style/HorizontalDividerStyle" />

        <com.quickblox.sample.chat.ui.widget.AttachmentPreviewAdapterView
            android:id="@+id/adapter_view_attachment_preview"
            style="@style/MatchWidth" />
    </LinearLayout>

    <View
        android:id="@+id/divider_chat"
        style="@style/HorizontalDividerStyle"
        android:layout_above="@+id/layout_chat_send_container" />

    <LinearLayout
        android:id="@+id/layout_chat_send_container"
        style="@style/MatchWidth"
        android:layout_alignParentBottom="true"
        android:background="?attr/colorPrimary"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/button_chat_attachment"
            style="@style/BorderlessImageButtonStyle"
            android:layout_gravity="center_vertical"
            android:onClick="onAttachmentsClick"
            android:src="@drawable/ic_action_attachment" />

        <EditText
            android:id="@+id/edit_chat_message"
            style="@style/WeightWidth"
            android:layout_height="wrap_content"
            android:hint="@string/chat_edit_text_hint"
            android:inputType="textShortMessage"
            android:maxLength="1024" />

        <ImageButton
            android:id="@+id/button_chat_send"
            style="@style/BorderlessImageButtonStyle"
            android:layout_gravity="center_vertical"
            android:onClick="onSendChatClick"
            android:src="@drawable/ic_send"
            android:text="@string/chat_send" />
    </LinearLayout>
</RelativeLayout>

Java代码

   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

清单

  <activity
        android:name=".ui.activity.ChatMenu"
        android:screenOrientation="portrait"
        android:theme="@style/ChatActivityTheme"
        android:windowSoftInputMode="stateHidden|adjustResize" />

风格

<style name="ChatActivityTheme" parent="AppTheme">
        <item name="android:windowBackground">@color/background_chat_color</item>

    </style>

如何避免顶部布局不能通过键盘向上移动,但编辑文本应在全屏活动中使用键盘移动

2 个答案:

答案 0 :(得分:0)

你试过这个吗?

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity>

doc here

那么你的整个布局都不会调整大小。如果你只想移动你的EditText,你必须测量键盘大小/可用屏幕(因为当键盘存在时它会更小)

没有“标准”方法可以防止调整大小并仅将View的一部分粘贴到键盘顶部(据我所知)

答案 1 :(得分:0)

尝试在你的androidmanifest.xml上使用它

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