当Android键盘打开时,如何仅推送编辑文本(带底部内容)?

时间:2017-04-22 13:58:48

标签: android xamarin android-softkeyboard

这是我的化妆。

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/chat_container"
        android:isScrollContainer="false"
        android:focusable="true"
        android:background="@drawable/test_woman"
        android:focusableInTouchMode="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_alignParentTop="true"
            android:id="@+id/headerContainer"
            android:isScrollContainer="false"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_height="@dimen/broadcast_live_stop_header"
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:background="#80000000"
                android:paddingLeft="@dimen/activity_vertical_margin"
                android:paddingRight="@dimen/activity_vertical_margin">
                <ImageView
                    android:id="@+id/camera"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:tint="@color/grey_camera"
                    android:src="@drawable/ic_photo_camera_white_36dp" />
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/stopLive"
                    android:layout_centerVertical="true"
                    android:text="Stop live"
                    android:textColor="#ffffff"
                    android:layout_toLeftOf="@id/camera"
                    android:layout_marginRight="@dimen/activity_vertical_margin"
                    android:background="@drawable/red_button_shape"
                    local:MvxBind="Click StopLive"
                    android:textSize="16sp" />
            </RelativeLayout>
        <!---->
            <MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/broadcast_live_stop_header"
                android:layout_marginLeft="@dimen/chat_message_margin_left_bottom_right"
                android:layout_marginBottom="@dimen/chat_message_container_margin_bottom"
                android:layout_marginRight="@dimen/chat_message_margin_left_bottom_right"
                android:id="@+id/messageList"
                local:MvxItemTemplate="@layout/item_recycler_view"
                local:MvxBind="ItemsSource Items" />
            <RelativeLayout
                android:id="@+id/inputMessageContainer"
                android:layout_height="@dimen/broadcast_live_stop_header"
                android:layout_alignParentBottom="true"
                android:layout_width="match_parent"
                android:paddingLeft="@dimen/activity_vertical_margin"
                android:paddingRight="@dimen/activity_margin_with_icon"
                android:background="@color/grey_background">
                <ImageView
                    android:id="@+id/likeBut"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:tint="@color/red_blur"
                    android:src="@drawable/ic_favorite" />
                <ImageView
                    android:id="@+id/emoji_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:tint="@color/dark_grey"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@id/likeBut"
                    android:src="@drawable/smiley" />
                <ImageView
                    android:id="@+id/send"
                    local:MvxBind="Click SendMessage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:tint="@color/dark_grey"
                    android:src="@drawable/ic_chevron_right_white" />
            <!---->
                <hani.momanii.supernova_emoji_library.Helper.EmojiconEditText
                    android:id="@+id/emojiInput"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_toLeftOf="@id/send"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/edit_text_shape"
                    android:layout_marginBottom="@dimen/chat_message_margin_bottom"
                    android:layout_marginTop="@dimen/chat_message_margin_bottom"
                    local:MvxBind="Text Message, Mode=TwoWay"
                    android:hint="Write your comment..."
                    android:layout_marginRight="@dimen/activity_margin_with_icon"
                    android:layout_marginLeft="5dp"
                    android:layout_toRightOf="@id/emoji_btn"
                    local:emojiconSize="28sp" />
            </RelativeLayout>
        </RelativeLayout>
    </RelativeLayout>

First screenSecond screen

  

我尝试了一切:

WindowSoftInputMode = Android.Views.SoftInput.AdjustPan,
WindowSoftInputMode = Android.Views.SoftInput.AdjustResize
this.Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan). 什么都没发生,内容总是在跳跃。我希望底部内容推高,但其他(包括背景图片)保持不变。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我认为您可能误解Android.Views.SoftInput.AdjustPan,使用AdjustPan,它会移动整个视图,而不会调整页面内容以显示键盘,适用于您的场景:

  

我希望底部内容推高,但其他(包括背景图片)留在原地。有什么建议吗?

你需要的只是:

this.Window.SetSoftInputMode(SoftInput.AdjustResize);