-
大小: 4KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-16
- 语言: 其他
- 标签: flowtaglayou
资源简介
flowtaglayout相关源码 直接copy到项目中即可使用。。。。。。。。。。。
代码片段和文件信息
package com.xj.hpqq.huopinquanqiu.widget.flowtaglayout;
import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 流式标签布局
* 原理:重写{@link ViewGroup#onMeasure(int int)}
* 和{@link ViewGroup#onLayout(boolean int int int int)}
* 方法
* Created by HanHailong on 15/10/19.
*/
public class FlowTagLayout extends ViewGroup {
private static final String TAG = FlowTagLayout.class.getSimpleName();
/**
* FlowLayout not support checked
*/
public static final int FLOW_TAG_CHECKED_NONE = 0;
/**
* FlowLayout support single-select
*/
public static final int FLOW_TAG_CHECKED_SINGLE = 1;
/**
* FlowLayout support multi-select
*/
public static final int FLOW_TAG_CHECKED_MULTI = 2;
/**
* Should be used by subclasses to listen to changes in the dataset
*/
AdapterDataSetObserver mDataSetObserver;
/**
* The adapter containing the data to be displayed by this view
*/
ListAdapter mAdapter;
/**
* the tag click event callback
*/
OnTagClickListener mOnTagClickListener;
/**
* the tag select event callback
*/
OnTagSelectListener mOnTagSelectListener;
/**
* 标签流式布局选中模式,默认是不支持选中的
*/
private int mTagCheckMode = FLOW_TAG_CHECKED_NONE;
/**
* 存储选中的tag
*/
private SparseBooleanArray mCheckedTagArray = new SparseBooleanArray();
public FlowTagLayout(Context context) {
super(context);
}
public FlowTagLayout(Context context AttributeSet attrs) {
super(context attrs);
}
public FlowTagLayout(Context context AttributeSet attrs int defstyleAttr) {
super(context attrs defstyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec heightMeasureSpec);
//获取Padding
// 获得它的父容器为它设置的测量模式和大小
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
//FlowLayout最终的宽度和高度值
int resultWidth = 0;
int resultHeight = 0;
//测量时每一行的宽度
int lineWidth = 0;
//测量时每一行的高度,加起来就是FlowLayout的高度
int lineHeight = 0;
//遍历每个子元素
for (int i = 0 childCount = getChildCount(); i < childCount; i++) {
View childView = getChildAt(i);
//测量每一个子view的宽和高
measureChild(childView widthMeasureSpec heightMeasureSpec);
//获取到测量的宽和高
int childWidth = childView.getMeasuredWidth();
int childHeight = childView.getMea
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12194 2017-12-29 17:00 flowtaglayout\FlowTagLayout.java
文件 193 2017-12-28 13:26 flowtaglayout\OnInitSelectedPosition.java
文件 239 2017-12-28 13:26 flowtaglayout\OnTagClickListener.java
文件 241 2017-12-28 13:26 flowtaglayout\OnTagSelectListener.java
目录 0 2018-06-13 14:28 flowtaglayout
----------- --------- ---------- ----- ----
12867 5
- 上一篇:基于QT的网络聊天室+收发数据及文件+源代码
- 下一篇:习语言安装使用教程.pdf
评论
共有 条评论