廢話不多說 先上圖
1.三種大小模式 ,依次小营勤、中率触、大
image.png
image.png
image.png
2.設(shè)置圓角
image.png
自行設(shè)置圓角大小(僅在非圓角模式生效)
image.png
3.鏤空模式(圓角支持自定義)
image.png
4.在控件設(shè)置數(shù)據(jù)
<com.uni.taggroupview.TagView
android:id="@+id/tag_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textList="隨時可看,帶家私,帶家電,隨時可看,帶家私,帶家電,靠近地鐵,貴,大型購物商場,停車場"
app:roundedCorners="5"
app:isHollowOut="true"
app:isRounded="false"
app:sizeMode="large"
/>
5.在代碼設(shè)置數(shù)據(jù)
// 公開設(shè)置數(shù)據(jù)方法
public void setDatas(List<String> texts) {
}
// 設(shè)置點(diǎn)擊回調(diào)
binding.tagView.setClickCallback((view, index) -> {
Log.e("TAG", "onClick: "+index);
});
// 設(shè)置長按回調(diào)
binding.tagView.setLongClickCallback((view, index) -> {
Log.e("TAG", "onLongClick: "+index);
return false;
});
6..文本顏色默認(rèn)白色 背景色默認(rèn)隨機(jī) 兩種顏色均可以指定
設(shè)置間距僅支持marginRight marginBottom; 也可以通過代碼來設(shè)置margin值
app:marginRight="5"
app:marginBottom="5"
7. v1.0.6增加兩種模式旧巾,背景色可定義為漸變背景房资,圓角可自定義
第一種 左側(cè)顯示單個字符蜕劝,右側(cè)內(nèi)容,如下圖轰异,默認(rèn)顯示第一個字符
image.png
代碼設(shè)置如下
<com.uni.taggroupview.TagView
android:id="@+id/tag_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isHollowOut="false"
app:isRounded="false"
app:roundedCorners="5"
app:sizeMode="small"
app:textList="隨時可看,帶家私,帶家電,隨時可看,帶家私,帶家電,靠近地鐵,貴實(shí)打?qū)?大型購物商場,停車場"
app:marginRight="5"
app:styleMode="1"
/>
8.第二種 左側(cè)顯示圖標(biāo)岖沛,右側(cè)內(nèi)容,如下圖
image.png
代碼設(shè)置如下
<com.uni.taggroupview.TagView
android:id="@+id/tag_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:isHollowOut="false"
app:isRounded="false"
app:roundedCorners="5"
app:sizeMode="small"
app:textList="隨時可看,帶家私,帶家電,隨時可看,帶家私,帶家電,靠近地鐵,貴實(shí)打?qū)?大型購物商場,停車場"
app:marginRight="5"
app:styleMode="2"
/>
自定義圓角
image.png
9.如果不喜歡漸變 色搭独,可以只設(shè)置一種顏色婴削,如下
int[] color=new int[]{Color.RED};
int[] color2=new int[]{Color.BLUE};
binding.tagView1.setLeftColor(color);
binding.tagView1.setRightColor(color2);
binding.tagView2.setLeftColor(color);
binding.tagView2.setRightColor(color2);
10.添加依賴
implementation 'com.gitee.Pino_W:tag_group:v1.0.9'