方便你在ImageView上添加标签:labelview
jopen
10年前
有时候,我们需要在一个ImageView上添加其它任何view。刚好LabelView能够帮助你,实现起来很方便。
</div> Import your project
Gradle
dependencies { compile 'com.lid.labelview:lib:0.1.1' }
If it doesn't work, please send me a emaillid.guan@gmail.comor create an issue.
Or
Copy LabelView.java into your project.
Create a Label
LabelView extends fromTextViewso you can treat it as aTextViewand use any of its method.
Usage:
LabelView label = new LabelView(this); label.setText("POP"); label.setBackgroundColor(0xff03a9f4); label.setTargetView(findViewById(R.id.text), 10, LabelView.Gravity.LEFT_TOP);
setTargetView parameters
setTargetView(findViewById(R.id.text), 10, LabelView.Gravity.LEFT_TOP)
- The second parameter states the distance between the edge of the bottom view and LabelView (unit dip)
- The third parameter states the side of where LabelView should appear on the bottom view. (onlyLEFT_TOPandRIGHT_TOP)
remove label
you can useremovemethod. eg:
label.remove();
LabelView in BaseAdpter
If you using LabelView in BaseAdpter and reuse of convertView, you have to generate label ID manual. eg:
public View getItemView(int position, View convertView, ViewHolder holder) { ...... // you have to generate label ID manual LabelView label = holder.getView(12345); if (label == null) { label = new LabelView(this); label.setId(12345); label.setBackgroundColor(0xffE91E63); label.setTargetViewInBaseAdapter(imageView, 138, 10, LabelView.Gravity.LEFT_TOP); } label.setText(your data); return convertView; }
setTargetViewInBaseAdapter parameters
- The second parameter means targetView width (unit dip).