【问题标题】:Prevent view from goes up with soft keyboard with adjust resize使用调整大小的软键盘防止视图上升
【发布时间】:2018-02-24 19:49:10
【问题描述】:

我的主要活动是android:windowSoftInputMode="adjustResize" 的片段的容器。我的布局包含底部按钮,这些按钮与软键盘一起使用,并且对于大多数片段逻辑都是可以接受的。但在一个片段中,我想防止底部按钮出现这种行为。如何在不改变 android:windowSoftInputMode="adjustResize" 的情况下实现这一点?我有这样结构的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/widget_toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_56dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

    <include
        android:id="@+id/container_company_header"
        android:layout_height="@dimen/dimen_55dp"
        android:layout_width="wrap_content"
        layout="@layout/container_company_header"
        android:layout_below="@+id/toolbar" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_service_review"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/container_bottom_buttons"
        android:layout_below="@+id/container_company_header"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        tools:listitem="@layout/item_review_linear" />

    <include
        android:id="@+id/container_bottom_buttons"
        layout="@layout/container_bottom_buttons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

【问题讨论】:

    标签: android android-softkeyboard


    【解决方案1】:

    你不能。如果按钮固定在RelativeLayout 的底部,并且您的活动因android:windowSoftInputMode="adjustResize" 而调整大小,那么您的按钮将被软键盘向上推。如果您不希望按钮移动,则必须更改这两件事之一。

    【讨论】:

    • 我可以只为这个片段生命周期以编程方式设置adjustResize吗?
    • getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2011-10-09
    • 2011-05-16
    相关资源
    最近更新 更多