【问题标题】:Android - AdjustResize won't work with external library that extends FrameLayoutAndroid - AdjustResize 不适用于扩展 FrameLayout 的外部库
【发布时间】:2017-03-20 07:19:39
【问题描述】:

我使用一个名为 DragListView here 的外部库。这个DragListView 扩展了一个FrameLayout,它在里面包含了一个RecyclerView。结构如下:

DragListView extends FrameLayout {
     RecyclerView mRecyclerView;
}

填充到 RecyclerView 中的项目包含 EditTextEditText 靠近屏幕顶部(如果出现软键盘,则不会被覆盖)可以正常工作。但是被软键盘覆盖的那个会获得焦点然后在调用myEditText.requestFocus();时立即失去焦点然后键盘覆盖EditText

这是我的活动布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.ui.activities.ChecklistsActivity">

<include layout="@layout/custom_action_bar"
    android:id="@+id/action_bar"/>

<com.woxthebox.draglistview.DragListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:id="@+id/recycler_view_checklists"
    />

    </LinearLayout>

android:layout_gravity="top" 在我的旧结构中为我工作一次,其中 DragListView 是RecyclerView 内的嵌套子项(我为RecyclerView 设置了最高重力),但在这种情况下它不再工作了。

我不能使用AdjustPan,因为它会将我的操作栏推开(但很遗憾,它有效)。我的应用程序不是全屏的(仍然可以看到状态栏,我认为它不是全屏的,如果我错了请纠正我)。我尝试了一些东西,但没有任何效果。

我在myEditText.requestFocus(); 之前致电myEditText.setFocusable(true);myEditText.setFocusableInTouchMode(true);

我将android:descendantFocusability="afterDescendants" 放入DragListView 或根LinearLayout

我尝试了不同的方式来调用键盘以弹出类似

InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

或使用收到getCurrentFocus(); Activity 的 KeyboardUtils

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);

还有一件事以防万一。我不知道我的“自定义”键盘是否与edtSubItemName.setImeActionLabel("Done", KeyEvent.KEYCODE_ENTER); 相关,因为我想要一个带有“完成”操作键的多行EditTextEditText 项的 xml 在这里:

<EditText
       android:id="@+id/edit_text_sub_checklist_item"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"             
       android:layout_marginLeft="@dimen/height_checklist_setting"
       android:layout_marginRight="@dimen/height_checklist_setting"
       android:inputType="text"
       android:imeOptions="actionDone"
       android:maxLength="256"
       android:textSize="@dimen/text_size_default"
       android:visibility="invisible" />

android:visibility="invisible" 是因为有一个按钮可以按下使其可见。

这几天我都生气了。我错过了什么吗?欢迎随时询问更多信息。

感谢大家的宝贵时间。

【问题讨论】:

    标签: android android-edittext keyboard android-recyclerview android-framelayout


    【解决方案1】:

    我通过在设置myDragListView.setLayoutManager(layoutManager);之前为布局管理器设置layoutManager.setStackFromEnd(true);解决了这个问题

    然后列表从最后一项开始,所以我只需在setAdapter 之后调用myDragListView.scrollToPosition(0); 使其像往常一样回到顶部。有趣的是物品的位置还是一样的(还是从上到下)所以没什么可做的。

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多