浮动操作按钮在相对布局中不浮动
Floating action button is not floating in relative layout
下面是我的登录活动的布局。
因此,当我单击 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>
将以下代码行添加到您的 AndroidManifest.xml 文件中,并包含您的特定 activity.
android:windowSoftInputMode="adjustResize"
您的布局在 RelativeLayout 中工作正常。
您需要更改您定义 Activity 的清单文件。
需要进行以下更改:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"
tools:ignore="LockedOrientationActivity">
下面是我的登录活动的布局。
因此,当我单击 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>
将以下代码行添加到您的 AndroidManifest.xml 文件中,并包含您的特定 activity.
android:windowSoftInputMode="adjustResize"
您的布局在 RelativeLayout 中工作正常。
您需要更改您定义 Activity 的清单文件。
需要进行以下更改:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"
tools:ignore="LockedOrientationActivity">