简体   繁体   English

软键盘隐藏edittext

[英]SoftKeyboard hides edittext

I have an EdiText at the bottom of my layout.The issue I was having is that when it gets focus the screen shifts upwards to give space to soft keyboard.To resolve it I added 我在EdiText的底部有一个EdiText ,我遇到的问题是,当它获得焦点时,屏幕会向上移动以为软键盘EdiText出空间。

android:windowSoftInputMode="adjustResize"

inside my Activity declaration in manifest .Now the problem is that the edittext hides behind the softkeyboard although screen doesn't shifts. 现在在清单中我的Activity声明中。问题是,尽管屏幕没有移动,但编辑文本仍隐藏在软键盘的后面。 If instead I put 相反,如果我放

android:windowSoftInputMode="adjustPan"

then the activity's main window shifts upward which i don't want. 然后活动的主窗口会向上移动,这是我不希望的。 How can i resolve this in such way that when EdiText gets focus activity's main window does NOT shift upwards to make room for the soft keyboard but the main window is resized including the EdiText so that keyboard comes below EdiText as seen in many apps. 我该如何解决这一问题,以便当EdiText获得焦点活动时,主窗口不会向上移动以为软键盘腾出空间,但是会调整包括EdiText在内的主窗口的大小,从而使键盘位于EdiText下方,这在许多应用程序中EdiText可以看到。

Layout 布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_feed">


    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center_horizontal|center_vertical" />



    <ListView
        android:id="@+id/comments"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#F7F7F7"
        android:paddingTop="10dp"
        android:layout_above="@+id/border_view_comment"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        android:paddingBottom="10dp"
        android:clipToPadding="false"
        android:scrollbarStyle="outsideOverlay" />

    <TextView
        android:id="@+id/empty_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/no_comment_msg"
        android:visibility="gone"/>

    <View
        android:id="@+id/border_view_comment"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/commentlayout"
        android:background="#C7C7C7"
        android:visibility="gone"/>


    <RelativeLayout
        android:id="@+id/commentlayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/comment_box_shadow"
        android:padding="10dp">

        <ImageView
            android:id="@+id/commentor_image"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginRight="15dp"
            />

        <ImageView
            android:id="@+id/clickPostComment"
            android:layout_width="30dp"
            android:layout_height="45dp"
            android:layout_alignParentRight="true"
            android:src="@drawable/post"
            android:textColor="@color/white" />

        <EditText
            android:id="@+id/commentsPost"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_alignTop="@id/commentor_image"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@id/clickPostComment"
            android:layout_toRightOf="@id/commentor_image"
            android:background="@drawable/comment_edittext_bg"
            android:hint="Comments"
            android:singleLine="true"
            android:maxLength="140"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColor="@color/title_gray"
            android:textColorHint="#d5d5d5"
            android:textSize="15sp" />

        <ImageView
            android:layout_width="25dp"
            android:layout_height="30dp"
            android:layout_alignTop="@id/commentsPost"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="-2dp"
            android:layout_toLeftOf="@id/commentsPost"
            android:scaleType="fitStart"
            android:src="@drawable/comment_shape" />
    </RelativeLayout>
</RelativeLayout>

make your view scrollable by embed your view inside Scrollview 通过将视图嵌入Scrollview使视图可滚动

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
   .....
    add your layout
   ......

</ScrollView>

If that doesn't help make you root layout as RelativeLayout and design your layout with RelativeLayout 如果这样不能帮助您将布局的根目录设置为RelativeLayout并使用RelativeLayout设计布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM