【问题标题】:Floating action button is not floating in relative layout浮动操作按钮在相对布局中不浮动
【发布时间】:2021-02-05 07:20:34
【问题描述】:

所以下面是我的登录活动的布局。

所以当我点击 EditText 时,键盘会打开,并且浮动操作按钮不会出现在键盘上方,如下所示

所以我想要实现的是floatingactionbutton应该在键盘打开时浮动,如下图所示......

下面是我的 MainActivity.xml 文件代码...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_centerHorizontal="true"
         app:srcCompat="@drawable/ic_launcher_foreground" />

    <EditText
        android:id="@+id/etemail"
        android:layout_width="230dp"
        android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
        android:ems="10"
        android:layout_below="@+id/textView3"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/etpw"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:ems="10"
        android:inputType="textPassword"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/textView4"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="53dp"
        android:clickable="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        app:srcCompat="@drawable/ic_arrow_forward" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_marginBottom="70dp"
        android:text="Forget password"
        android:layout_alignParentBottom="true"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView"
        android:text="@string/Signin"
        android:textSize="23dp"
        android:layout_marginLeft="80dp"
    />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_marginLeft="80dp"
        android:layout_marginBottom="3dp"
        android:text="@string/usrname"
        app:layout_constraintBottom_toTopOf="@+id/etemail"
        app:layout_constraintStart_toStartOf="@+id/textView2" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:text="@string/pwd"
        android:layout_below="@+id/etemail"
        android:layout_marginLeft="80dp"
        />

</RelativeLayout>

【问题讨论】:

    标签: android android-relativelayout floating-action-button


    【解决方案1】:

    将以下代码行添加到您的 AndroidManifest.xml 文件中,其中包含您的特定活动。

    android:windowSoftInputMode="adjustResize"
    

    【讨论】:

      【解决方案2】:
      1. 您的布局在 RelativeLayout 中运行良好。

      2. 您需要更改定义 Activity 的清单文件。

      需要进行以下更改:

      <activity android:name=".activity.MainActivity"
                  android:screenOrientation="portrait"
                  android:windowSoftInputMode="adjustResize|stateHidden"
                  tools:ignore="LockedOrientationActivity">
      

      【讨论】:

        猜你喜欢
        • 2018-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-25
        • 2016-11-26
        相关资源
        最近更新 更多