2 android joker Android_joker 于 2016.03.25 14:09 提问

这种布局怎么解决...谢谢各位大神

图片说明

3个回答

gwpking
gwpking   2016.03.25 14:26

问题没说清楚,你要思路?代码

bdmh
bdmh   Ds   Rxr 2016.03.25 14:46

flowlayout,给你源码

 package com.jrj.tougu.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

public class FlowLayout extends ViewGroup {
    private float mVerticalSpacing; //每个item纵向间距
    private float mHorizontalSpacing; //每个item横向间距

    public FlowLayout(Context context) {
        super(context);
    }
    public FlowLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setHorizontalSpacing(float pixelSize) {
        mHorizontalSpacing = pixelSize;
    }
    public void setVerticalSpacing(float pixelSize) {
        mVerticalSpacing = pixelSize;
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int selfWidth = resolveSize(0, widthMeasureSpec);

        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();

        int childLeft = paddingLeft;
        int childTop = paddingTop;
        int lineHeight = 0;

        //通过计算每一个子控件的高度,得到自己的高度
        for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {
            View childView = getChildAt(i);
            LayoutParams childLayoutParams = childView.getLayoutParams();
            childView.measure(
                    getChildMeasureSpec(widthMeasureSpec, paddingLeft + paddingRight,
                            childLayoutParams.width),
                    getChildMeasureSpec(heightMeasureSpec, paddingTop + paddingBottom,
                            childLayoutParams.height));
            int childWidth = childView.getMeasuredWidth();
            int childHeight = childView.getMeasuredHeight();

            lineHeight = Math.max(childHeight, lineHeight);

            if (childLeft + childWidth + paddingRight > selfWidth) {
                childLeft = paddingLeft+childWidth;
                childTop += mVerticalSpacing + lineHeight;
                lineHeight = childHeight;
            } else {
                childLeft += childWidth + mHorizontalSpacing;
            }
        }

        int wantedHeight = childTop + lineHeight + paddingBottom;
        setMeasuredDimension(selfWidth, resolveSize(wantedHeight, heightMeasureSpec));
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int myWidth = r - l;

        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();

        int childLeft = paddingLeft;
        int childTop = paddingTop;

        int lineHeight = 0;

        //根据子控件的宽高,计算子控件应该出现的位置。
        for (int i = 0, childCount = getChildCount(); i < childCount; ++i) {
            View childView = getChildAt(i);

            if (childView.getVisibility() == View.GONE) {
                continue;
            }

            int childWidth = childView.getMeasuredWidth();
            int childHeight = childView.getMeasuredHeight();

            lineHeight = Math.max(childHeight, lineHeight);

            if (childLeft + childWidth + paddingRight > myWidth) {
                childLeft = paddingLeft;
                childTop += mVerticalSpacing + lineHeight;
                lineHeight = childHeight;
            }
            childView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
            childLeft += childWidth + mHorizontalSpacing;
        }
    }
}
Android_joker
Android_joker 谢谢分享
2 年多之前 回复
u011113654
u011113654   2016.03.25 14:47
Android_joker
Android_joker 你太棒了
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
鸡蛋灌饼
今天晚上出去跑步,回来的时候已经11:20了,看到三教后面拆迁区卖鸡蛋灌饼的正在收拾家当,我对老胡说:“挣钱不容易啊,起早贪黑的!”老胡却说:“在学校,卖鸡蛋灌饼的比老师挣钱多!”还根据地上一堆蛋壳给我算了一笔帐,一天少说也得挣二三百块钱。我就想了,要是只是为了挣钱,卖鸡蛋灌饼也不错啊,难怪有清华毕业卖猪肉的。看来,还得抓点紧,在学校里预定一个铺面,要是哪天混不下去了,就卖灌饼,就冲着我这双握了十
明天是我的生日,谢谢大家捧场
明天是我的生日,谢谢大家捧场
javaFX8手册
基于javaFX的手册,高质量英文版,谢谢各位大神下载应用
vs2010+opencv2.4.9运行时候出现问题?求助各位
参考书目是OpenCV3 编程入门 程序是: # include using namespace cv; int main () { VideoCapture capture("1.avi"); while (1) { Mat frame; capture>>frame; imshow("reading video", frame); waitKey(60000);
Java实现Hadoop大表join
这是一个课堂作业,用来join订单和用户,在这里记录下来。源数据csv order.csv ID_O,Order_No,ID_P 1,24351,2 2,43567,1 3,77895,156 person.csv Id_P,LastName,FirstName,Address,City 1,Snow,Jon,GreatWall,Winterfell 2, Lannister,Tyrion,Cast
1032 各位数字求和
#include using namespace std; int main(){ int a,s=0; cin>>a; while(a>0){ s+=a%10; a=a/10; } cout<<s<<endl; return 0; }
64位机子,vs2010配置opencv2.4.9遇到问题解决
最近换了64位的主机,准备把之前做过的程序都整理一下,然后之前
英语口语练习四十之地道口语:感谢及回应感谢的英语表达
表达感谢有很多英语运用方式:1.Thank you.谢谢作为最普遍的表达感谢的语句,与此相同的意思表达为Thanks。2.Thank you very much.非常感谢在Thank you 后面加上程度词,表达了对对方的感激程度之深,此外还有:Thanks a lot 非常感谢;Thank you so much 非常感谢;Thanks a bundle 非常感谢”a bundle”常作为量词,为
TXT在线小说管理器
不知道哪里写错了,各位大神帮忙指点下,告诉怎么进行修改
大神,麻烦解决下异常 谢谢
做了一个C#局域网五子棋游戏,每次注册或者登陆都会异常,还会显示端口号被占用,请问大概是什么问题引发的异常:“System.Threading.ThreadAbortException”(位于 GobangClass.dll 中)线程 0x1e54 已退出,返回值为 0 (0x0)。“ClientGobang.exe”(CLR v2.0.50727: ClientGobang.exe): 已加载“...