簡體   English   中英

SoftKeyboard在android中向上推布局

[英]SoftKeyboard pushes up the layout in android

我有一個使用片段的活動。 在片段中,我有自定義工具欄、一個列表和一個 EditTextView。 當鍵盤在此活動中可見時,它會向上推布局。 如何防止工具欄位於其原始位置。 以下代碼寫在我的片段中:

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

    <TextView
        android:id="@+id/channel_title"
        android:paddingLeft="10dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:background="@color/black"
        android:textColor="@color/white"
        android:textSize="16sp"
        android:visibility="gone"
        android:layout_below="@id/layout_alert_top"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:id="@+id/layout_alert_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:background="@color/app_blue"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/layout_channel_back_view"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="true"
            android:focusable="true">

            <ImageView
                android:id="@+id/title_bar_left_menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/ic_menu_white_32"/>
        </RelativeLayout>

        <TextView
            android:id="@+id/tv_screen_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:text="@string/channel_title"
            android:layout_centerInParent="true"
            android:textSize="24sp"
            android:textColor="@color/white_text"/>

        <RelativeLayout
            android:id="@+id/channels_sliding_menu"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:clickable="true"
            android:focusable="true">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/ic_tab_channels_white"/>
        </RelativeLayout>

    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_below="@+id/channel_title"
        android:isScrollContainer="false"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/layout_list_alerts"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/zero_conversation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:textColor="@color/dark_gray_text"
                android:layout_centerInParent="true"
                android:text="Empty"
                android:visibility="gone"/>

            <RelativeLayout
                android:id="@+id/layout_type_message"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal"
                android:background="@color/gray">

                <EditText
                    android:id="@+id/et_type_message"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toLeftOf="@+id/layout_send_message"
                    android:background="@drawable/square_round_corners"
                    android:hint="Type your message.."
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="10dp"
                    android:padding="5dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:textColorHint="@color/black"
                    android:textSize="16sp"/>

                <Button
                    android:id="@+id/layout_send_message"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:layout_alignParentRight="true"
                    android:padding="5dp"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    android:background="@color/transparent"
                    android:textColor="@color/dark_gray_text"
                    android:layout_centerInParent="true"
                    android:text="Send"/>
            </RelativeLayout>

            <ListView
                android:id="@+id/conversation_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/layout_type_message"
                android:divider="@null"
                android:listSelector="@color/transparent"
                android:stackFromBottom="true"
                android:transcriptMode="normal"
                />
        </RelativeLayout>

        <FrameLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:baselineAligned="false" >
        </FrameLayout>

        <ListView
            android:id="@+id/channels_list"
            android:background="@color/gray"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null"
            android:layout_gravity="right"
            android:choiceMode="singleChoice" />
    </android.support.v4.widget.DrawerLayout>


</RelativeLayout>

您好,嘗試在清單文件的活動標簽中應用此屬性,並讓我知道您是否可以獲得所需的輸出。 好的。

 android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

> XML 文件`:

<?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_alert_main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF">


    <RelativeLayout
        android:id="@+id/layout_alert_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:orientation="horizontal"
        android:visibility="visible">

        <RelativeLayout
            android:id="@+id/layout_channel_back_view"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="true"
            android:focusable="true">

            <ImageView
                android:id="@+id/title_bar_left_menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="#FFFFFF" />
        </RelativeLayout>

        <TextView
            android:id="@+id/tv_screen_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:text="Title"
            android:textColor="#FFFFFF"
            android:textSize="24sp" />

        <RelativeLayout
            android:id="@+id/channels_sliding_menu"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:clickable="true"
            android:focusable="true">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/ic_logo" />
        </RelativeLayout>

    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:isScrollContainer="false">

        <RelativeLayout
            android:id="@+id/layout_list_alerts"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/zero_conversation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="Empty"
                android:textColor="#000000"
                android:textSize="16sp"
                android:visibility="gone" />

            <RelativeLayout
                android:id="@+id/layout_type_message"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:background="#000000"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/et_type_message"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="5dp"
                    android:layout_toLeftOf="@+id/layout_send_message"
                    android:background="#FFFFFF"
                    android:hint="Type your message.."
                    android:padding="5dp"
                    android:singleLine="true"
                    android:textColor="#000000"
                    android:textColorHint="#000000"
                    android:textSize="16sp" />

                <Button
                    android:id="@+id/layout_send_message"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="10dp"
                    android:background="#000000"
                    android:padding="5dp"
                    android:text="Send"
                    android:textColor="#FFFFFF"
                    android:textSize="16sp"
                    android:textStyle="bold" />
            </RelativeLayout>

            <ListView
                android:id="@+id/conversation_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/layout_type_message"
                android:divider="@null"
                android:stackFromBottom="true"
                android:transcriptMode="normal" />
        </RelativeLayout>

        <FrameLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:baselineAligned="false"></FrameLayout>

        <ListView
            android:id="@+id/channels_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:background="#000000"
            android:choiceMode="singleChoice"
            android:divider="@null"
            tools:listtem="@layout/demo_layout" />
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

在 Ur 布局中使用滾動視圖或使用 manifest.xml 中的代碼。

<activity android:windowSoftInputMode="adjustPan">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM