[英]How to make drawable circle shape with count
I really appreciate if someone can help me with using how to drawable circle view with count as like my below image. 我真的很感激有人能帮助我如何使用计数绘制圆形视图,就像我的下图所示。
I wrote some code for my requirement but it's showing rectangular shape but i want circular shape.. 我为我的要求写了一些代码,但显示的是矩形,但是我想要圆形。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@color/colorPrimary" />
<solid android:color="@color/colorLightSky" />
<padding
android:bottom="2dp"
android:left="10dp"
android:right="10dp"
android:top="2dp" />
</shape>
<FrameLayout
android:id="@+id/group_attachment_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="3dp"
android:background="@drawable/linear_layout_border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/ic_group"
android:tint="@color/rosecolor" />
</RelativeLayout>
<TextView
android:id="@+id/members_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginBottom="3dp"
android:background="@drawable/test_circle"
android:gravity="center"
android:minWidth="15dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="0"
android:textColor="#fff"
android:textStyle="bold"
android:visibility="visible" />
</FrameLayout>
Try this it looks as you want 试试看它看起来像你想要的
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners
android:radius="10dip"/>
<solid
android:color="#2196F3" />
<stroke
android:width="2dip"
android:color="#FFF" />
<padding
android:left="2dip"
android:right="2dip"
android:top="2dip"
android:bottom="2dip" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
Use this code to draw a circle and put it as background of your TextView
and make its android:gravity="center"
使用此代码绘制一个圆并将其用作
TextView
背景,并使它成为android:gravity="center"
Change height and width according to your need. 根据需要更改高度和宽度。
Try following drawable 尝试跟随可绘制
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item xmlns:android="http://schemas.android.com/apk/res/android">
<shape>
<solid android:color="#58050505" />
<corners
android:topLeftRadius="3dp"
android:topRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
/>
</shape>
</item>
</selector>
Use this for the TextView background
将此用于TextView背景
inside drawable folder 内部可绘制文件夹
badge_background.xml badge_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="@color/purple"
android:startColor="@color/purple"></gradient>
<corners android:radius="100dp"></corners>
<stroke
android:width="0.5dp"
android:color="@color/white" />
</shape>
The TextView
TextView
<TextView
android:id="@+id/serial_no"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="top|start"
android:layout_marginTop="5dp"
android:background="@drawable/badge_background"
android:gravity="center|center_vertical"
android:maxLines="1"
android:text="1"
android:textColor="@android:color/white"
android:textSize="13sp"
android:textStyle="bold" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.