【发布时间】:2021-10-03 22:04:11
【问题描述】:
我正在开发一个关于原生 Android 的辅助项目。 我想在这篇文章所附的图片中添加该功能。我想知道如何在Android中实现这个功能以及它通常被称为什么。 请帮我。 谢谢Example of what I am intending to achieve
【问题讨论】:
标签: android xml kotlin android-layout
我正在开发一个关于原生 Android 的辅助项目。 我想在这篇文章所附的图片中添加该功能。我想知道如何在Android中实现这个功能以及它通常被称为什么。 请帮我。 谢谢Example of what I am intending to achieve
【问题讨论】:
标签: android xml kotlin android-layout
您可以通过使用带有android:gravity="bottom" 的FrameLayout 和带有适当约束的嵌套LinearLayout 或ConstraintLayout 并表示LinearLayout 来实现这一点。
以FrameLayout 为例
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<androidx.appcompat.widget.Toolbar
android:background="@color/lightGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
id="@+id/bottomToolbar"
android:layout_gravity="bottom"
android:gravity="center"
android:foregroundGravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
</LinearLayout>
</FrameLayout>
以ConstraintLayout 为例
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.Toolbar
app:layout_constraintTop_toTopOf="parent"
android:background="@color/lightGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
id="@+id/bottomToolbar"
app:layout_constraintBottom_toBottomOf="parent"
android:gravity="center"
android:foregroundGravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
<Button
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Btn"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
结果
我用过按钮,但你明白要点,你可以使用 ImageButtons、图像、文本,随便你。
除此之外,您还可以聆听“软键盘”的出现和消失,并为height 或底部工具栏的可见性设置动画,使其看起来更酷。 IE:当它出现时显示底部栏,当它消失时将其删除。
【讨论】: