【问题标题】:Soft Keyboard hides part of layout?软键盘隐藏部分布局?
【发布时间】:2016-03-10 22:56:32
【问题描述】:

我有一个问题,当单击布局底部的EditText 时,会显示一个软键盘。问题是当我单击EditText 并且软键盘显示时,我可以滚动浏览我的ListView,但是我在列表视图之前声明的布局,即ActionBarRelativeLayout,是两者都隐藏。在我的AndroidManifest 中,我声明:android:windowSoftInputMode="stateAlwaysHidden|adjustPan"。我认为这是因为我没有添加 ScrollView 作为布局的父级,但是当我这样做时,没有任何改变。这是我的尝试:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/comments_layout">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"
        android:id="@+id/comments_appbar">

    <android.support.v7.widget.Toolbar android:id="@+id/comments_toolbar"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:background="?attr/colorPrimary" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    </android.support.design.widget.AppBarLayout>

    <RelativeLayout
        android:layout_below="@id/comments_appbar"
        android:id="@+id/view_post"
        android:layout_width="match_parent"
        android:paddingRight="5dp"
        android:paddingLeft="5dp"
        android:orientation="horizontal"
        android:layout_height="175dp"
        android:background="#e6e6e6">

        <com.facebook.drawee.view.SimpleDraweeView
            android:layout_marginTop="15dp"
            android:id="@+id/poster_picture"
            android:layout_width="75dp"
            android:layout_height="75dp"
            android:layout_marginLeft="10dp"
            fresco:placeholderImage="@mipmap/blank_prof_pic"
            fresco:roundedCornerRadius="5dp"
            />

        <TextView
            android:layout_marginLeft="5dp"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@id/poster_picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp"
            android:textStyle="bold"
            android:id="@+id/poster_name"/>

        <TextView
            android:layout_alignParentRight="true"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@id/poster_name"
            android:layout_marginLeft="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp"
            android:id="@+id/post_date"/>

        <TextView
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/poster_picture"
            android:layout_below="@id/poster_name"
            android:textSize="20sp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/view_status" />

    </RelativeLayout>

            <ListView
                android:id="@+id/lv_comments_feed"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/send_message"
                android:layout_below="@+id/view_post">
            </ListView>

        <LinearLayout
            android:id="@+id/send_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/write_comment"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_weight="5"
                android:gravity="top|left"
                android:hint="Comment back!"
                android:inputType="textMultiLine"
                android:background="@color/white"
                android:scrollHorizontally="false" />

            <Button
                android:id="@+id/send_comment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:gravity="center"
                android:text="send"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

</RelativeLayout>
    </ScrollView>

开头的RelativeLayoutActionBar 都被隐藏了,但是当我的软键盘弹出并单击我的EditText 时,我仍然可以滚动浏览我的ListView。有想法该怎么解决这个吗?谢谢!

【问题讨论】:

    标签: android android-layout keyboard android-softkeyboard adjustpan


    【解决方案1】:

    代替

    android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

    写下来

    android:windowSoftInputMode="adjustPan|adjustResize"

    会有帮助的

    【讨论】:

    • 这无济于事,因为我的EditText 消失了,我正在输入的区域似乎被键盘隐藏了(它与EditText 重叠)。此外,如果有什么我想在单击 EditText 时简单地向上推布局,因为它可以帮助我看到键盘,EditText,如果我向上或向下滚动,我可以看到布局。跨度>
    • 根据文档developer.android.com/guide/topics/manifest/…Setting multiple values in either group — multiple "state..." values, for example — has undefined results
    【解决方案2】:

    我通过使用解决了这个问题

    android:isScrollContainer="false"
    

    在滚动视图和清单文件中添加

    android:windowSoftInputMode="adjustResize"
    

    【讨论】:

      【解决方案3】:

      我在AndroidManifest 文件中使用了以下代码:

      android:windowSoftInputMode="adjustResize"
      

      【讨论】:

        猜你喜欢
        • 2021-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-28
        • 2016-06-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多