【发布时间】: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