不需要自定义View给TextView添加标签。
build.gradle添加
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
代码块:
public class TestLableActivity extends Activity {
TextView tvLable;
TextView tvLable2;
private int width;
private int height;
private String lableStr = "标签1";
private String lableStr2 = "标签2";
private String content = "内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_textlable);
tvLable = findViewById(R.id.tv_lable);
tvLable2 = findViewById(R.id.tv_lable2);
width = getResources().getDisplayMetrics().widthPixels;
height = getResources().getDisplayMetrics().heightPixels;
height = height / 38;