android多行标签热点示例
package com.test.mytest.widget;
import java.util.list;
import android.content.context;
import android.os.handler;
import android.util.attributeset;
import android.widget.linearlayout;
import android.widget.textview;
public class mutiplelabellayout extends linearlayout {
public mutiplelabellayout(context context, attributeset attrs) {
super(context, attrs);
}
public mutiplelabellayout(context context) {
super(context);
}
public mutiplelabellayout(context context, list<string> list) {
super(context);
mlist = list;
mcontext = context;
}
@override
protected void onattachedtowindow() {
super.onattachedtowindow();
new handler().postdelayed(new runnable() {
@override
public void run() {
init();
}
}, 500);
}
private void init() {
this.setorientation(linearlayout.vertical);
linearlayout row = new linearlayout(mcontext);
row.setorientation(linearlayout.horizontal);
this.addview(row);
int rowwidth = this.getmeasuredwidth();
int viewsumwidth = 0;
for (string label : mlist) {
textview labelview = new textview(mcontext);
labelview.settext(label);
labelview.setpadding(10, 0, 10, 0);
labelview.setlayoutparams(new layoutparams(
layoutparams.wrap_content, layoutparams.wrap_content));
row.addview(labelview);
labelview.measure(0, 0);
viewsumwidth += labelview.getmeasuredwidth();
if (viewsumwidth > rowwidth) {
row.removeview(labelview);
row = new linearlayout(mcontext);
row.setorientation(linearlayout.horizontal);
this.addview(row);
row.addview(labelview);
labelview.measure(0, 0);
viewsumwidth = labelview.getmeasuredwidth();
}
// system.out.println("viewsumwidth: " + viewsumwidth);
// system.out.println("rowwidth: " + rowwidth);
}
}
private list<string> mlist;
private context mcontext;
}
上一篇: android调试工具adb命令大全
下一篇: 合上笔记本后,如何继续下载?