【问题标题】:SoftKeyboard pushes up the layout in androidSoftKeyboard在android中推高布局
【发布时间】:2016-02-11 11:26:05
【问题描述】:

我有一个使用片段的活动。在片段中,我有自定义工具栏、一个列表和一个 EditTextView。当键盘在此 Activity 中可见时,它会向上推布局。如何防止工具栏位于其原始位置。 以下代码写在我的片段中:

    <?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>

【问题讨论】:

  • 你到底想要什么?你想获得软键盘,但又不想布局被推高?
  • @Strider yeh 完全正确
  • 我已经删除了我的帖子,因为它没有回答你的问题,srry

标签: android layout android-softkeyboard


【解决方案1】:

您好,请尝试在 Manifest 文件中的 Activity Tag 中应用此属性,如果您知道,请告诉我 能不能得到你想要的输出。好的。

 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>

【讨论】:

  • @Ehsan 它在我身边工作得很好,我已经检查过了。我重用了您的 XML 并进行了检查。当键盘打开时,只有底部面板向上滑动而不是自定义工具栏。请检查我的更新答案。请在您身边检查一次并告诉我。谢谢。
【解决方案2】:

在 Ur Layout 中使用滚动视图或使用 manifest.xml 中的代码。

<activity android:windowSoftInputMode="adjustPan">

【讨论】:

    【解决方案3】:

    【讨论】:

    • 伙计,我没有否决您的回答,我不知道为什么有人对您的回答这样做。感谢您分享您的知识谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    相关资源
    最近更新 更多