android多行標(biāo)簽熱點(diǎn)示例
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;
}
相關(guān)文章
Android編程獲取網(wǎng)絡(luò)時(shí)間實(shí)例分析
這篇文章主要介紹了Android編程獲取網(wǎng)絡(luò)時(shí)間,結(jié)合實(shí)例形式對(duì)比分析了Android通過訪問網(wǎng)絡(luò)及通過GPS獲取網(wǎng)絡(luò)時(shí)間的具體步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01Android串口開發(fā)之使用JNI實(shí)現(xiàn)ANDROID和串口通信詳解
這篇文章主要給大家介紹了關(guān)于Android串口開發(fā)之使用JNI實(shí)現(xiàn)ANDROID和串口通信的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01Android 7.0系統(tǒng)webview 顯示https頁面空白處理方法
今天小編就為大家分享一篇Android 7.0系統(tǒng)webview 顯示https頁面空白處理方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07Android 實(shí)現(xiàn)切圓圖作為頭像使用實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)切圓圖作為頭像使用實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-12-12Android獲取當(dāng)前應(yīng)用分配的最大內(nèi)存和目前使用內(nèi)存的方法
今天小編就為大家分享一篇關(guān)于Android獲取當(dāng)前應(yīng)用分配的最大內(nèi)存和目前使用內(nèi)存的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02