admin 管理员组

文章数量: 1184232

这是我的效果图

下面讲一下配置步骤

1.清单文件Activity中里配置

android:windowSoftInputMode="adjustResize"

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

<LinearLayout
    xmlns:android="http://schemas.android/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/apk/res/android"
xmlns:app="http://schemas.android/apk/res-auto"
xmlns:tools="http://schemas.android/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/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>

在布局里添加android:fitsSystemWindows=“true”后,会多出一块空白,这里贴上解决办法。

1、新建CustomLinearLayout继承LinearLayout,之后替换之前的根布局(ConstraintLayout、RelativeLayout同理)

 /**
 * 作者:G
 * ClassName:CustomLinearLayout
 * 时间:2020/7/30  9:35 AM
* 概述: 解决android:fitsSystemWindows="true"后顶部出现白条
 */
public class CustomLinearLayout extends LinearLayout {
public CustomLinearLayout(Context context) {
    super(context);
}

public CustomLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
protected boolean fitSystemWindows(Rect insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        insets.left = 0;
        insets.top = 0;
        insets.right = 0;
    }
    return super.fitSystemWindows(insets);
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
    } else {
        return insets;
    }
}
}

完美解决!

本文标签: 页面 遮挡 输入框 输入法 顶上去