【问题标题】:How to Set a Button at a fixed position even when respective Activity has ScrollView即使相应的 Activity 具有 ScrollView,如何在固定位置设置按钮
【发布时间】:2018-04-08 18:25:29
【问题描述】:

当 Activity 有 ScrollView 组件时,有没有办法使用一些不可滚动的视图?

我希望我的按钮的行为类似于下面问题中的按钮,我也希望它固定在 UI 的底部:

how to set a button at a fixed location on the bottom of UI?

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent ">

    <FrameLayout
        android:id="@+id/map_frameview"
        android:layout_width="match_parent"
        android:layout_height="200dp">
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="20dp">
    </LinearLayout>

</LinearLayout>
</ScrollView>

提前致谢!

【问题讨论】:

  • 让按钮远离 ScrollView 并将其定位在底部。

标签: android android-scrollview


【解决方案1】:

您在问题中附加的链接显示了您如何做到这一点。您可以为此使用RelativeLayout。这个想法是,您需要告诉一个按钮留在屏幕底部并告诉滚动视图保持在按钮上方以及它的可滚动内容,例如:

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

    <Button
        android:id="@+id/btnMy"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btnMy">

        <LinearLayout
            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"
            android:layout_above="@id/btnMy"
            android:orientation="vertical">

            <FrameLayout
                android:id="@+id/map_frameview"
                android:layout_width="match_parent"
                android:layout_height="200dp">
            </FrameLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="20dp">
            </LinearLayout>

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    相关资源
    最近更新 更多