<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    咖啡伴侶

    呆在上海
    posts - 163, comments - 156, trackbacks - 0, articles - 2

    DashboardLayout之scroll版本AutoTableLayout

    Posted on 2013-03-12 13:33 oathleo 閱讀(1564) 評論(0)  編輯  收藏 所屬分類: Android
    iosched 里的DashboardLayout 在scroll里好像有點(diǎn)問題,一個類就事情,沒時間調(diào)了,自己寫了個

    1 1 import android.content.Context;
     2 import android.view.View;
     3 import android.widget.LinearLayout;
     4 
     5 public class AutoTableLayout extends LinearLayout {
     6 
     7     private int mMaxChildWidth = 0;
     8     private int mMaxChildHeight = 0;
     9 
    10     //列數(shù)
    11     private int column = 0;
    12     //是否自定義列數(shù)
    13     private boolean isCustomColumn = false;
    14     
    15     public AutoTableLayout(Context context) {
    16         super(context, null);
    17     }
    18 
    19     public AutoTableLayout(Context context, int col) {
    20         super(context, null);
    21         column = col;
    22         isCustomColumn = true;
    23     }
    24 
    25     @Override
    26     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    27         mMaxChildWidth = 0;
    28         mMaxChildHeight = 0;
    29 
    30         final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
    31         final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
    32 
    33         final int count = getChildCount();
    34         for (int i = 0; i < count; i++) {
    35             final View child = getChildAt(i);
    36             if (child.getVisibility() == GONE) {
    37                 continue;
    38             }
    39 
    40             child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
    41 
    42             mMaxChildWidth = Math.max(mMaxChildWidth, child.getMeasuredWidth());
    43             mMaxChildHeight = Math.max(mMaxChildHeight, child.getMeasuredHeight());
    44         }
    45 
    46         int width = resolveSize(mMaxChildWidth, widthMeasureSpec);
    47 
    48         // 每行個數(shù)
    49         if (!isCustomColumn) {
    50             column = (int) Math.floor((double) width / mMaxChildWidth);
    51         }
    52          
    53         int row = (int) Math.ceil((double) count / column);
    54 
    55         int height = mMaxChildHeight * row;
    56         setMeasuredDimension(width, height);
    57 
    58     }
    59 
    60     @Override
    61     protected void onLayout(boolean changed, int l, int t, int r, int b) {
    62         int width = r - l;
    63         int height = b - t;
    64         
    65         final int count = getChildCount();
    66         
    67         int left, top;
    68         int col, row;
    69         
    70         int gap = (width - column * mMaxChildWidth) / (column + 1);
    71         
    72         for (int i = 0; i < count; i++) {
    73             final View child = getChildAt(i);
    74 
    75             row = (int) Math.floor( (double)i / column);
    76             col = i % column;
    77 
    78             left = l + (col + 1) * gap + col * mMaxChildWidth;
    79             top = t + row * mMaxChildHeight;
    80             
    81             
    82             child.layout(left, top, left + mMaxChildWidth, top + mMaxChildHeight);
    83         }
    84     }
    85 
    86 }
    主站蜘蛛池模板: 亚洲人成色7777在线观看| 亚洲AV成人噜噜无码网站| 免费A级毛片无码A∨| 亚洲国产成人久久三区| 国产男女猛烈无遮挡免费视频| 日韩一区二区三区免费播放| 国产亚洲婷婷香蕉久久精品| 69国产精品视频免费| 国产亚洲精品美女久久久久 | 亚洲午夜精品一级在线播放放| APP在线免费观看视频| 亚洲不卡视频在线观看| 日批日出水久久亚洲精品tv| 99视频免费播放| 免费人成网站永久| 亚洲天堂中文字幕在线观看| 亚洲精品麻豆av| 日韩免费一区二区三区在线| 五月婷婷免费视频| ASS亚洲熟妇毛茸茸PICS| 在线日韩日本国产亚洲| 女人18毛片水真多免费看| 国产午夜无码精品免费看动漫| 亚洲精华液一二三产区| 亚洲国产一区国产亚洲| 亚洲国产综合精品一区在线播放| 中字幕视频在线永久在线观看免费| 91av免费在线视频| 亚洲AV成人无码久久WWW| 亚洲高清视频在线播放| 中文字幕在亚洲第一在线| 免费看片免费播放| 中国xxxxx高清免费看视频| 亚洲免费日韩无码系列| 亚洲AV无码AV日韩AV网站| 亚洲国产日韩女人aaaaaa毛片在线| 亚洲人JIZZ日本人| 亚洲国产精品无码久久九九| 男男AV纯肉无码免费播放无码 | 污污视频网站免费观看| 亚洲成a人片在线观看精品|