键盘关闭使我的观点之一消失了

时间:2018-07-24 19:19:01

标签: android android-fragments

我正在使用活动和片段。该活动具有相机样式布局,如下所示:

enter image description here

当用户单击快门按钮时,照片下方的区域将替换为表单:

enter image description here

右上角的 x 是活动布局的一部分,其可见性最初设置为View.GONE(也尝试过View.INVISIBLE)。当片段打开时,我使该视图可见,如屏幕截图所示。

我遇到的问题是,当聚焦EditText时,键盘会向上推布局,并且在 x 关闭时不会恢复。 x 保持不可见,但是当我在该区域单击时,仍会触发其点击监听器。当我单击EditText时, x 会很快出现,然后随着键盘的出现而消失。

您知道什么可能导致此问题吗?

活动布局(ID为ivExit的ImageView是 x ):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rlCameraHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#000"
    android:paddingLeft="10dp"
    android:paddingStart="10dp"
    android:paddingRight="10dp"
    android:paddingEnd="10dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/ivExit"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/baseline_clear_white_18dp" />
</RelativeLayout>

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/flPreview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintDimensionRatio="H, 1:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<RelativeLayout
    android:id="@+id/rlPlaceholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="50dp"
        android:gravity="center_horizontal">
    <ImageView
        android:layout_alignLeft="@+id/ivCaptureImage"
        android:layout_alignStart="@+id/ivCaptureImage"
        android:layout_marginRight="140dp"
        android:tint="@color/colorSecondary"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:src="@drawable/baseline_camera_rear_white_18dp" />

    <ImageView
        android:layout_alignRight="@+id/ivCaptureImage"
        android:layout_alignEnd="@+id/ivCaptureImage"
        android:layout_width="30dp"
        android:layout_height="25dp"
        android:tint="@color/colorSecondary"
        android:backgroundTint="@color/colorSecondary"
        android:src="@drawable/baseline_flash_on_white_18dp" />
    </LinearLayout>

    <ImageView
        android:id="@+id/ivCaptureImage"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_centerInParent="true"
        android:src="@drawable/camera_shutter_selector" />
</RelativeLayout>
</LinearLayout>

片段布局:

<?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="wrap_content"
android:background="@color/white">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_centerVertical="true"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:layout_marginBottom="?attr/actionBarSize">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TO"
            android:textSize="14dp"
            android:fontFamily="sans-serif-smallcaps"/>
        <EditText
            android:id="@+id/etTo"
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/tiny_text_size"
            android:imeOptions="actionNext"
            android:inputType="text"
            android:fontFamily="sans-serif"
            android:backgroundTint="#BDBDBD" />
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BY"
            android:textSize="14dp"
            android:fontFamily="sans-serif-smallcaps" />
        <EditText
            android:id="@+id/etBy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textSize="@dimen/tiny_text_size"
            android:imeOptions="actionDone"
            android:inputType="text"
            android:fontFamily="sans-serif"
            android:backgroundTint="#BDBDBD" />
    </RelativeLayout>

</LinearLayout>
<FrameLayout
    android:id="@+id/flGo"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:layout_alignParentBottom="true"
    android:background="@color/colorSecondary">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:fontFamily="sans-serif"
        android:text="GO" />
</FrameLayout>
</RelativeLayout>

我在活动的onCreate方法中将其可见性设置为View.GONE,并在调用该片段时将其可见性设置为View.VISIBLE。另外值得注意的是,此活动以全屏模式运行(即顶部没有通知栏)。

感谢任何帮助!

0 个答案:

没有答案