如何在垂直滚动视图上使用浮动按钮? [英] How to use Floating Button Over Vertical Scroll View?

查看:78
本文介绍了如何在垂直滚动视图上使用浮动按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gmail Android应用浮动按钮

The Gmail Android App Floating Button

我想在Android的滚动视图上添加一个浮动按钮.这样,即使我滚动布局,在这种情况下,按钮也应在给定位置(右下)保持不变.就像Gmail android移动应用一样,它们的右下角有一个完整的发送邮件"按钮,并且背景是可滚动的.

I want to add a floating button over a scroll view in Android. Such that, even if I scroll the layout, the button should remain constant at the given position (bottom-right) in this case. Just like the Gmail android mobile app, they have a send mail button intact at the bottom-right and the background is scrollable.

推荐答案

使约束视图内部的滚动视图不使主父布局成为滚动视图.

make the Scroll View inside constraint layout don't make the main parent layout the scroll view.

<?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">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        tools:srcCompat="@tools:sample/avatars[0]" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>
</android.support.constraint.ConstraintLayout>

这篇关于如何在垂直滚动视图上使用浮动按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆