Android custom viewgroup, I also play waterfall stream

Source: Internet
Author: User

Let's take a look,

There are some differences in the layout effect implemented in ". The height of each grid is irregular, that is, the legendary waterfall flow layout. Generally, this effect can be achieved by using third-party controls, if the image is not loaded, it can be directly written in xml for implementation, but there will be a lot of code;

The following is the full code of the custom viewgroup:

WaterfullLayout String tag = "balance" columns = 2 rows = 0 margin = 10 count = 0 mMaxChildWidth = 0 mMaxChildHeight = 0 WaterfullLayout (Context context, AttributeSet attrs, (attrs! ===. GetInteger (R. styleable. myGridLayout_numColumns, 2 = (). getInteger (R. styleable. myGridLayout_itemMargin, 2 (context, attrs, 0 onMeasure (widthMeasureSpec, = 0 = 0 = (count = 0 = count % columns = 0? Count/columns: count/columns + 1; top [] = (I = 0; I <rows; I ++) {(j = 0; j <columns; j ++) {View child =. getChildAt (I * columns + (child = (child. getVisibility () = + = lp. height + = + onLayout (changed, l, t, r, height = B-t; width = r-l; (count = 0 gridW = (width-margin * (columns + 1)/columns; gridH = 0; left = 0 top [] = (I = 0; I <rows; I ++) {(j = 0; j <columns; j ++ ){ View child =. getChildAt (I * columns + (child = (child. getTag ()! = &-= GetMax (top)-= j * gridW + margin * (j + 1 + margin, left ++ = j * gridW + margin * (j + 1 + = + gridW, top [j] ++ = getMax (max = array [0 (I = 0; I <array. length; I ++ (max <=View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.