解决聊天页面解决软键盘遮挡住输入框,和输入法把整个页面顶上去的问题

这是我的效果图

在这里插入图片描述在这里插入图片描述

下面讲一下配置步骤

1.清单文件Activity中里配置

android:windowSoftInputMode="adjustResize"

在这里插入图片描述

2.根目录layout布局 加入 android:fitsSystemWindows=“true”

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    >

3.Recyview或Listview 设置属性

<ListView
    android:id="@+id/robot_lv"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    android:listSelector="@android:color/transparent"
    android:transcriptMode="alwaysScroll" >
</ListView>

下面附上我的完整布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activitys.RobotActivity">
<RelativeLayout
    android:id="@+id/relat_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_60"
    android:background="@color/colorBlack">
    <TextView
        android:id="@+id/txt_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="@dimen/dp_10"
        android:gravity="center"
        android:text="@string/title"
        android:textColor="@color/colorWhite"
        android:textSize="20sp" />

    <ImageView
        android:id="@+id/iv_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="@dimen/dp_20"
        android:layout_marginTop="@dimen/dp_10"
        android:scaleType="centerCrop"
        android:src="@drawable/base_back_left" />
</RelativeLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    >
<!-- transcriptMode 自动向下滚动    alwaysScroll一直向下滚动状态;   divider设置间隔线效果 ;   listSelector设置没有滑动效果 -->
   <com.scwang.smartrefresh.layout.SmartRefreshLayout
   android:id="@+id/refreshLayout"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1">
<ListView
    android:id="@+id/robot_lv"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    android:listSelector="@android:color/transparent"
    android:transcriptMode="alwaysScroll" >
</ListView>
  </com.scwang.smartrefresh.layout.SmartRefreshLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:background="@color/holo_orange_light"
    android:orientation="horizontal" >
    <EditText
        android:hint="请输入想说的话…"
        android:visibility="gone"
        android:background="@drawable/edittext_bck"
        android:id="@+id/et_sendText"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:layout_margin="7dp"
        android:paddingBottom="7dp"
        android:paddingTop="7dp" />
    <TextView
        android:visibility="visible"
        android:background="@drawable/edittext_bck"
        android:id="@+id/te_sendText"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:layout_margin="7dp"
        android:paddingBottom="7dp"
        android:paddingTop="7dp" />
    <Button
        android:id="@+id/btn_send"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_margin="7dp"
        android:background="@drawable/send_bck"
        android:text="发送" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

猜你喜欢

转载自blog.csdn.net/qq_43143981/article/details/85250555
今日推荐