java - 按钮停留在底部时水平和垂直滚动

标签 java android

我有一个 Android 应用程序,其中有一个可以显示自定义数据的 Activity。

我需要水平和垂直的滚动条,以便在尺寸大于屏幕时可以看到数据。

所以我尝试添加一个Horizo​​ntalScrollView,它添加了水平滚动,但现在按钮不再粘在屏幕底部。我该怎么办?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activities.UserModeAdvancedActivity"
tools:showIn="@layout/activity_user_mode_advanced">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <HorizontalScrollView
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TableLayout
            android:id="@+id/tableLayout_user_mode_advanced"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginStart="24dp"
            android:layout_weight="1"
            android:padding="6dp"
            android:stretchColumns="*"
            app:layout_constraintStart_toStartOf="parent"
            tools:layout_editor_absoluteY="0dp">
        </TableLayout>

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:gravity="center_horizontal">
            <Button
                android:id="@+id/buttonAlarmOverview"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:background="@drawable/rounded_button"
                android:onClick="onButtonClick"
                android:text="@string/button_show_more" />
        </LinearLayout>
    </LinearLayout>
    </HorizontalScrollView>
</ScrollView>

</android.support.constraint.ConstraintLayout>

最佳答案

嘿,试试下面的代码:-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="10"
android:orientation="vertical">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="9"
    android:fillViewport="true">

    <HorizontalScrollView
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TableLayout
                android:id="@+id/tableLayout_user_mode_advanced"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginStart="24dp"
                android:layout_weight="1"
                android:padding="6dp"
                android:stretchColumns="*"
                app:layout_constraintStart_toStartOf="parent"
                tools:layout_editor_absoluteY="0dp">
            </TableLayout>
        </LinearLayout>
    </HorizontalScrollView>
</ScrollView>
<LinearLayout
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:gravity="center_horizontal">
    <Button
        android:id="@+id/buttonAlarmOverview"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_button"
        android:onClick="onButtonClick"
        android:text="@string/button_show_more" />
</LinearLayout>

关于java - 按钮停留在底部时水平和垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57395631/

相关文章:

java - 执行者未完成所有任务

java - Smack API 抛出 item-not-found(404) 异常

java - 在 JNI 调用 API 中工作时可以安全地将对象传递给 C 函数吗?

android - 谷歌在 Android 上为展示的标记绘制弹跳动画?

android - YouTube 直播 API LiveChatMessages

java - RenderRequest 上的协议(protocol)重定向

java - 关于如何异常退出程序的问题

android - Google Play 商店是否提供任何应用激活机制

android - 如何为 Android 应用程序提供多语言支持

Android 通用 XML 解析器