手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android多行标签热点示例
android多行标签热点示例
摘要:复制代码代码如下:packagecom.test.mytest.widget;importjava.util.List;importandr...

复制代码 代码如下:

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多行标签热点示例】相关文章:

Android之网络通信案例分析

Android开发之OpenGL ES 画多边形

android layout 按比例布局的代码

Android图片翻转动画简易实现代码

Android 自定义View的使用介绍

Android 通过onDraw实现在View中绘图操作的示例

listview Button始终放在底部示例

android广播接收者实例

Android 判断网络状态

Android 异步加载图片分析总结

精品推荐
分类导航