微曦晨光 2018-12-28 11:39 采纳率: 100%
浏览 4773
已采纳

在fragment中edittext被键盘顶上去之后,输入框的下面外边距被遮挡住了

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="@color/color_23ce66"
        android:gravity="center"
        android:paddingTop="20dp"
        android:text="健康服务"
        android:textColor="@color/color_ff"
        android:textSize="18sp" />

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/rv"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingVertical="10dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginHorizontal="15dp"
            android:layout_weight="1"
            android:background="@drawable/rectangle_stroke_ec_17dp"
            android:hint="回复"
            android:id="@+id/et_send"
            android:paddingHorizontal="10dp"
            android:textColor="@color/color_33"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/tv_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:background="@drawable/rectangle_solid_23ce66_17dp"
            android:paddingHorizontal="25dp"
            android:paddingVertical="5dp"
            android:text="发送"
            android:textColor="@color/color_ff" />
    </LinearLayout>

</LinearLayout>

图片说明
图片说明
就是这么个意思,有没有大牛知道怎么做,让输入框的部分显示完整

//==================分割=======================//
2019年1月3日,解决方案记录

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_ff"
    android:clickable="true"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/ll_content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:background="@color/color_23ce66"
            android:gravity="center"
            android:paddingTop="20dp"
            android:text="健康服务"
            android:textColor="@color/color_ff"
            android:textSize="18sp" />

        <com.jcodecraeer.xrecyclerview.XRecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingVertical="10dp">

        <EditText
            android:id="@+id/et_send"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginHorizontal="15dp"
            android:layout_weight="1"
            android:background="@drawable/rectangle_stroke_ec_17dp"
            android:hint="回复"
            android:paddingHorizontal="10dp"
            android:textColor="@color/color_33"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/tv_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:background="@drawable/rectangle_solid_23ce66_17dp"
            android:paddingHorizontal="25dp"
            android:paddingVertical="5dp"
            android:text="发送"
            android:textColor="@color/color_ff" />
    </LinearLayout>

    <View
        android:id="@+id/v"
        android:layout_width="0dp"
        android:layout_height="0dp" />
</LinearLayout>
 etSend.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                //获取当前界面可视部分
                ((Main2Activity) getActivity()).getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
                //获取屏幕的高度
                int screenHeight = ((Main2Activity) getActivity()).getWindow().getDecorView().getRootView().getHeight();
                //此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
                int heightDifference = screenHeight - r.bottom;

                lockContentHeight();
                unlockContentHeightDelayed(heightDifference);


            }
        });


   /**
     * 锁定内容高度,防止跳闪
     */
    private void lockContentHeight() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llContent.getLayoutParams();
        params.height = llContent.getHeight();
        params.weight = 0.0F;
    }


    /**
     * 释放被锁定的内容高度
     */
    public void unlockContentHeightDelayed(final int heightDifference) {
        etSend.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (llContent == null) {
                    return;
                }
                ((LinearLayout.LayoutParams) llContent.getLayoutParams()).weight = 1.0F;
                ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
                layoutParams.height = heightDifference - SizeUtils.dp2px(55);
                v.setLayoutParams(layoutParams);
            }
        }, 10L);
    }

  • 写回答

2条回答

  • 木子开今心 2018-12-28 06:28
    关注

    一般的做法是写一个跟键盘登高的view。
    https://github.com/Jacksgong/JKeyboardPanelSwitch
    github上有一些解决方案,不过原理也是一样的,监控键盘弹出,等高view可见。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择