流式布局:
FlowGroupView
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
public class FlowGroupView extends ViewGroup {
/**
* 储存所有的view 按行记录
*/
private List<List<View>> mAllViews = new ArrayList<List<View>>();
/**
* 记录每一行的高度
*/
private List<Integer> mLineHeight = new ArrayList<Integer>();
private String TAG = "TAG";
public FlowGroupView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public FlowGroupView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FlowGroupView(Context context) {
super(context);
}
/**
* 所有childView的位置的布局
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// 当前行的最大高度
int lineHeight = 0;
// 存储每一行所有的childView
List<View> lineViews = new ArrayList<View>();
int left = 0;
int top = 0;
// 得到总行数
int lineNums = mAllViews.size();
for (int i = 0; i < lineNums; i++)
{
// 每一行的所有的views
lineViews = mAllViews.get(i);