深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 654|回复: 1
打印 上一主题 下一主题

android.support.design.widget.FloatingActionButton

[复制链接]

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
跳转到指定楼层
楼主
发表于 2019-5-22 21:43:33 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zhgc 于 2019-5-22 21:46 编辑
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout     
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:id="@+id/contentView"
  5.     android:orientation="vertical"     
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent">
  8.     <android.support.design.widget.FloatingActionButton
  9.         android:id="@+id/fab"
  10.         android:layout_width="wrap_content"
  11.         android:layout_height="wrap_content"
  12.         android:layout_alignParentBottom="true"
  13.         android:layout_alignParentRight="true"
  14.         android:onClick="onClick"
  15.         android:layout_marginRight="10dp"
  16.         android:layout_marginBottom="10dp"/>
  17. </RelativeLayout>
复制代码

  1. public void onClick(View v) {
  2.     switch (v.getId()) {
  3.         case R.id.fab:
  4.             Snackbar.make(findViewById(R.id.contentView), "Snackbar", Snackbar.LENGTH_SHORT).show();
  5.             break;
  6.     }
  7. }
复制代码
回复

使用道具 举报

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
沙发
 楼主| 发表于 2019-5-22 21:57:04 | 只看该作者
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.design.widget.CoordinatorLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"
  5.     android:id="@+id/contentView"
  6.     android:orientation="vertical"
  7.     android:layout_width="match_parent"
  8.     android:layout_height="match_parent">
  9.     <LinearLayout
  10.         android:id="@+id/anchorView"
  11.         android:layout_width="match_parent"
  12.         android:layout_height="match_parent"
  13.         android:orientation="vertical"/>
  14.     <android.support.design.widget.FloatingActionButton
  15.         android:id="@+id/fab"
  16.         android:layout_width="wrap_content"
  17.         android:layout_height="wrap_content"
  18.         app:layout_anchor="@id/anchorView"
  19.         app:layout_anchorGravity="bottom|right"
  20.         android:onClick="onClick"
  21.         android:layout_marginRight="10dp"
  22.         android:layout_marginBottom="10dp"/>
  23. </android.support.design.widget.CoordinatorLayout>
复制代码


CoordinatorLayout 提供了两个属性用来设置 FAB 的位置:

layout_anchor:设置 FAB 的锚点,我们熟悉的 PopupWindow 也有类似概念。
layout_anchorGravity:设置相对锚点的位置,如bottom|right表示 FAB 位于锚点的右下角。

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-6-29 07:31 , Processed in 0.064808 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表