简体   繁体   English

我如何才能在我的 ui 背景中为 fab 按钮“剪出”圆形?

[英]How would I be able to “cut out” a circular shape for a fab button in my ui background?

我想要的

I'm trying to achieve the same as what's boxed in the image only I'm a programmer and I'm not sure how to start.我正在尝试实现与图像中装箱相同的内容,只是我是一名程序员,但我不知道如何开始。

Could this be achieved with a drawable?这可以通过drawable来实现吗? If so, would yo be able to point me in the right direction, or is it much more complex and something a graphics designer would need to achieve?如果是这样,您能否为我指明正确的方向,还是它更复杂,图形设计师需要实现的目标?

You can simply do this using the help of Material BottomAppBar along with Floating Action Button(FAB) .您可以使用Material BottomAppBarFloating Action Button(FAB)的帮助来简单地做到这一点。 You need to simply place both of them under the NestedScrollView of the layout which is shown below您只需将它们都放在如下所示的布局的NestedScrollView

<androidx.coordinatorlayout.widget.CoordinatorLayout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Note: A RecyclerView can also be used -->
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="100dp"
        android:clipToPadding="false">

        <!-- Scrollable content -->

    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
        app:navigationIcon="@drawable/ic_menu_24dp"
        app:menu="@menu/bottom_app_bar"
        />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_add_24dp"
        app:layout_anchor="@id/bottomAppBar"
        />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Set these attributes accordingly to achieve the shape what you want.相应地设置这些属性以实现您想要的形状。 Use fabCradleMargin and fabCradleRoundedCornerRadius attributes in BottomAppBar to set the rounded Corner and margin.使用fabCradleMarginfabCradleRoundedCornerRadius在属性BottomAppBar设定圆角和保证金。

Kindly refer to the official documentation for more information about implementation.有关实施的更多信息,请参阅官方文档。

You need to have a basic knowledge of how to create custom Path in Android using code or XML I would suggest not doing something like this, before learning about the same您需要对如何使用代码或 XML 在 Android 中创建自定义Path有基本的了解,我建议在学习相同之前不要做这样的事情

Here is a similar build up that can help you是一个类似的构建,可以帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置圆形FAB按钮 - How to set a circular FAB button 无法以编程方式隐藏圆弧菜单中的 fab 按钮。 试过 upload.hide(); 无法弄清楚如何隐藏 fab 按钮 - Unable to hide fab button in arc menu programmatically. tried upload.hide(); Not able to figure out how to hide fab button 如何使用自定义形状的 fab 按钮制作底部栏? - How make Bottombar with custom shape fab button? 如何使FAB按钮的形状像三角形 - How to make shape of FAB button to be like triangle 如何连续制作Fab按钮的动画(放大/缩小)? - How to Animate a Fab button (zoom in/out) continuously? 如何在android上更改浮动操作按钮(FAB)的形状? - How to change the shape of Floating Action Button (FAB) on android? 圆角方形背景形状,右上角有一个圆形 - Rounded square background shape with cut-out circle in top right 带阴影的圆形按钮,如 5.0 FAB - Circular button with shadow like 5.0 FAB 如何将 FAB 塑造为圆角按钮(药丸形状),类似于联系人应用程序的联系人详细信息屏幕? - How to shape a FAB to be rounded corners button (pill shape), similar to in contact-details screen of Contacts app? 我怎样才能使矩形的形状背景在底部边缘有一个锐利的切口? - How can i make the shape background for the rectangle have a sharp cut in the bottom edges?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM