Android开发右上角数字红点效果
往往需要控件右上角有个数字红点提醒用户
一、思路:
就是用TextView显示数字红点,慢慢调位置
二、效果图:
三、关键代码:
<ImageView
android:id="@+id/aiv_img"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@android:color/transparent"
android:src="@mipmap/ic_system_notify"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<TextView
android:id="@+id/tv_unread_count"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:includeFontPadding="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
app:layout_constraintRight_toRightOf="@id/aiv_img"
app:layout_constraintTop_toTopOf="@id/aiv_img"
android:layout_marginRight="-2dp"
android:layout_marginTop="-2dp"
android:background="@drawable/aliwx_unread_hint"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="10sp"
android:text="9" />
四、项目demo源码结构图:
有问题或者需要完整源码的私信我