Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我的键盘弹出时,如何隐藏元素?_Java_Android_Android Studio - Fatal编程技术网

Java 当我的键盘弹出时,如何隐藏元素?

Java 当我的键盘弹出时,如何隐藏元素?,java,android,android-studio,Java,Android,Android Studio,我看到过一些类似的问题,但他们想让事情显露出来,我想把它们隐藏起来。 基本上,我的RelativeLayout中有一堆元素,当活动显示时,键盘弹出,因为我有一个editText,底部对齐的元素沿着键盘向上移动,我不希望这样,我希望它们保持隐藏,你知道我该如何实现吗? 这是我的活动的xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/

我看到过一些类似的问题,但他们想让事情显露出来,我想把它们隐藏起来。 基本上,我的RelativeLayout中有一堆元素,当活动显示时,键盘弹出,因为我有一个editText,底部对齐的元素沿着键盘向上移动,我不希望这样,我希望它们保持隐藏,你知道我该如何实现吗? 这是我的活动的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:id="@+id/invoices_layout"
    tools:context=".NavManager">

    <RelativeLayout
        android:id="@+id/mcr_bar_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:visibility="visible">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:layout_marginTop="15dp"
            android:text="Agregar Productos"
            android:textColor="@android:color/white"
            android:textSize="34sp" />

        <TextView
            android:id="@+id/textGrid2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="0dp"
            android:text="Grupo MkTech Solutions"
            android:textColor="@android:color/white"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/txtproducto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="0dp"
            android:layout_marginTop="92dp"
            android:layout_marginEnd="0dp"
            android:hint="Ej: Refresco Natural"
            android:inputType="text"
            android:textColor="@color/white"
            android:textSize="15sp"
            app:backgroundTint="@color/white" />

        <ImageButton
            android:id="@+id/btnbuscar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/txtproducto"
            android:layout_alignEnd="@+id/txtproducto"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="0dp"
            android:onClick="onClickSwitch"
            app:srcCompat="@drawable/research" />

        <TextView
            android:id="@+id/txttotal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:padding="10dp"
            android:textColor="@color/WhiteBgText"
            android:textSize="15sp" />

        <ImageButton
            android:id="@+id/btnlimpiarcarro"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:onClick="onClickCleanCart"
            android:padding="10dp"
            app:srcCompat="@drawable/quit" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="0dp"
            android:layout_marginTop="150dp"
            android:layout_marginBottom="50dp"
            android:fillViewport="true">

            <TableLayout
                android:id="@+id/tableInvoices"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="0dp"
                android:stretchColumns="*"></TableLayout>

        </ScrollView>

    </RelativeLayout>

</LinearLayout>


scrollview之前的最后两个元素是需要隐藏的元素。

将以下内容添加到清单中的活动中:

android:windowSoftInputMode="adjustPan"
从:

活动的主窗口的大小不会调整为软键盘腾出空间。相反,窗口的内容会自动平移,以便当前焦点不会被键盘遮挡,用户可以随时看到他们正在键入的内容。这通常不如调整大小,因为用户可能需要关闭软键盘才能接触到窗口的模糊部分并与之交互


根据我对您问题的理解,您不希望键盘将UI元素推到布局的底部

要实现这一点,您只需将以下行放入清单活动标记中:

android:windowSoftInputMode="adjustNothing"

您可以调用
view.setVisibility(view.GONE)
在要隐藏的视图上,当显示键盘时,您应该寻找触发此方法的方法检查我是否正确理解了问题,一个简单的解决方案是调用元素
setVisibility(View.GONE)
当键盘显示时。这实际上不会隐藏视图,但会调整视图,使聚焦的编辑文本位于键盘上方。但是也许可以解决这个问题。@Omarmneh根据布局和可用视图的数量,它可以工作。然而,我知道情况并非总是如此。