首页 > 解决方案 > 如何使 Jetpack compose 元素出现在 android 的键盘顶部?

问题描述

在 XML 中让按钮粘在屏幕底部并在弹出时粘在键盘上非常简单,我们可以做这样的事情

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

//the ui views

    <TableLayout
    android:id="@+id/m_table_menu"
    style="@style/table_layout_style">

    <View style="@style/view_style" />

        <TableRow style="@style/table_row_button_style">
        //This button sticks to the bottom of the screen or to the keyboard when its open
        <Button
            android:id="@+id/save_user_name"
            style="@style/green_bottom_sticky_button"
            android:background="@drawable/green_disabled_ripple_rectangular_button"
            android:enabled="false"
            android:text="@string/next" />

        </TableRow>

    </TableLayout>

</RelativeLayout>

我们将如何在 Jetpack compose 中复制它?

标签: androidandroid-jetpack-composeandroid-jetpack-compose-listandroid-jetpack-compose-scaffoldandroid-jetpack-compose-surface

解决方案


我不确定 XML 是如何工作的,因为它没有重力或高度的定义。

但是,如果您希望视图始终位于列的底部,您可以制作一个单独Box的按钮,并提供最大尺寸和内容重力Bottom


推荐阅读