首页 > 解决方案 > 无法使用键盘 Android 向上移动视图

问题描述

我已经经历了各种答案,但是当键盘可见时无法向上移动我的视图。我在 recyclerview 中有一个编辑文本,其焦点键盘可见。我希望 tv_character_limit 文本在键盘可见时向上移动。我需要用 z-index 显示字符限制文本。我已将 windowSoftInputMode 设置为针对活动和视图寻呼机中的片段进行调整大小,我已添加了 java 代码:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

谢谢你的帮助。下面是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rel_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/pink">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar_post" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_status"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />

    <TextView
        android:id="@+id/tv_character_limit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="30dp"
        android:text="@string/character_limit"
        android:textColor="@color/tap_to_type"
        android:textSize="15dp" />
</FrameLayout>

标签: androidandroid-recyclerview

解决方案


使用RelativeLayout 代替FrameLayout,当EditText 获得焦点时,只需调用类似于layout_above 的RelativeLayout 类方法来更改TextView 的位置。


推荐阅读