[英]Floating action button is not floating in relative layout
So below is the layout of my loginactivity.所以下面是我的登录活动的布局。
So when I click on the EditText the keyboard open ups and the floating action button doesn't come above keyboard as shown below因此,当我单击 EditText 时,键盘会打开,并且浮动操作按钮不会出现在键盘上方,如下所示
So what I want to achieve is floatingactionbutton should float up when keyboard opens as shown in below image....所以我想要实现的是floatingactionbutton应该在键盘打开时浮动,如下图所示......
Below is my MainActivity.xml file code...下面是我的 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>
Your layout is working fine in RelativeLayout.您的布局在 RelativeLayout 中运行良好。
You need to change the manifest file where you have defined your Activity.您需要更改定义 Activity 的清单文件。
The following changes are required:需要进行以下更改:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"
tools:ignore="LockedOrientationActivity">
Add Following line of code to you AndroidManifest.xml file with your specific activity.将以下代码行添加到您的AndroidManifest.xml文件以及您的特定活动。
android:windowSoftInputMode="adjustResize"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.