Android Editext 随软键盘向上,不被软键盘遮挡

2019-08-11  本文已影响0人  浪子彦

先上图

在做之前,查了不少博客,都写的不够详细,也试了好几种:

(这部分为复制粘贴)

问题:一开始我用的相对布局,结果发现edittext   会被键盘所覆盖,本人也是菜鸡。开始了慢慢的解决道路。

     1.发现在Manifest中 <activity >项中添加这个属性 android:windowSoftInputMode ,具体就不介绍了,自己百度

关键词 android:windowSoftInputMode。        !! !!!但是缺点   整体布局会压缩  或者看不到顶部   这不是我想要的。

    2.继续百度后发现有人教用 :改用在AndroidMaifest.xml中使用的stateHidden|adjustResize,其中stateHidden是为了让首次进入页面是阻止软件盘的弹出,adjustResize是压缩布局。

用这种方法时,有一下注意事项:

a. 布局中必须有ListView或者ScrollView。

b. ListView或ScroolView中的属性layout_weight必须比较大。

c. ListView或ScroolView的属性layout_height一定要设置成wrap_content.

最终解决,在布局文件里完美搞定:

上布局文件xml:

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

<FrameLayout

    android:layout_height="match_parent"

    android:layout_width="match_parent"

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout     //  RelativeLayout 放不需要随键盘动的部分

        android:id="@+id/re_aaa"

        android:layout_marginBottom="50dp"

        android:layout_width="match_parent"

        android:layout_height="match_parent">

        <com.yangfan.neican.view.CustomTitleBar

            android:id="@+id/title_bar"

            app:left_button_visible="true"

            app:title_text=""

            app:title_text_color="@color/DarkGrey"

            app:right_button_visible="false"

            android:layout_width="match_parent"

            android:layout_height="@dimen/title_heigh">

        </com.yangfan.neican.view.CustomTitleBar>

        <WebView

            android:id="@+id/webview"

            android:layout_below="@+id/title_bar"

            android:layout_width="match_parent"

            android:layout_height="match_parent">

        </WebView>

        <View

            android:layout_width="match_parent"

            android:layout_height="1dp"

            android:background="#EEEEEE"

            />

    </RelativeLayout>

    <LinearLayout       //   随键盘动的部分

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:fitsSystemWindows="true"

        android:gravity="center_vertical"

        android:layout_gravity="bottom"

        android:orientation="horizontal">

        <ImageView

            android:layout_width="22dp"

            android:layout_height="22dp"

            android:layout_marginStart="15dp"

            android:src="@drawable/iv_collection" />

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="33dp"

            android:layout_marginStart="15dp"

            android:layout_marginTop="8dp"

            android:layout_marginEnd="15dp"

            android:layout_marginBottom="8dp"

            android:background="@drawable/bg_evaluation"

            android:gravity="center_vertical"

            android:orientation="horizontal">

            <android.support.v7.widget.AppCompatImageView

                android:layout_width="18dp"

                android:layout_height="18dp"

                android:layout_marginStart="17dp"

                android:src="@drawable/iv_print" />

            <android.support.v7.widget.AppCompatEditText

                android:id="@+id/et_evaluation"

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:layout_marginStart="7dp"

                android:hint="写评论..."

                android:background="@null"

                android:textColorHint="#333333"

                android:textSize="13sp" />

        </LinearLayout>

    </LinearLayout>

</FrameLayout>

注意:以上属性,别遗漏   android:fitsSystemWindows="true"

这就是完美解决方案。

上一篇 下一篇

猜你喜欢

热点阅读