首页 > 解决方案 > 自定义浮动操作按钮

问题描述

请帮帮我。我怎么能像这样做工厂。我必须使用什么,我可以做到这一点。也许你知道,我可以读到我的问题?

是否有任何样本/示例来执行这种转换?

我尝试使用背景,但它不起作用

在此处输入图像描述

标签: androidfloating-action-button

解决方案


制作此视图时出现问题。

  • FloatingActionButton 隐藏所有视图。所以你的点视图不能放在FAB上。所以我们必须制作 ImageView 而不是 FAB。

把它放在你的布局中。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/blue_circle"
        android:padding="15dp"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:layout_width="13dp"
        android:layout_height="13dp"
        android:layout_gravity="top|right"
        android:src="@drawable/red_circle" />

</FrameLayout>

在里面创建新的xmlres>drawable>blue_circle_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <gradient
        android:endColor="#8e81fc"
        android:startColor="#7264EA" />
</shape>

在里面创建新的xmlres>drawable>red_circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#ff0000" />
</shape>

输出将是这样的:

图片


推荐阅读