浮动动作按钮上的徽章计数 [英] Badge count on Floating action button
本文介绍了浮动动作按钮上的徽章计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android中的浮动操作按钮"前显示计数徽章.我使用FrameLayout来实现这一点.我的代码在这里
I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />
<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />
</FrameLayout>
我将计数徽章显示在FAB下方,如下所示
I get the count badge below the FAB, as shown below
我需要把计数徽章放在FAB的前面.
I need the count badge to be in front of the FAB.
推荐答案
对于此问题,解决方案为android:elevation="7dp"
.但是您正在寻找这样的东西,然后使用下面的代码:
For this problem solution is android:elevation="7dp"
. But you are looking for something like this then use bellow code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/margin.2">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_cart"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/margin.2"
app:srcCompat="@drawable/ic_add_shopping_cart"
app:backgroundTint="@color/colorPrimaryDark" />
<TextView
android:id="@+id/text_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="7dp"
android:gravity="center"
android:textColor="@color/white"
android:layout_alignParentRight="true"
android:textSize="@dimen/text.size.small"
android:background="@drawable/bg_fab"
tools:text="10" />
</RelativeLayout>
</RelativeLayout>
这篇关于浮动动作按钮上的徽章计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文