老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

AndroidRadioGroup實現(xiàn)自動換行的方法-創(chuàng)新互聯(lián)

這期內容當中小編將會給大家?guī)碛嘘PAndroid RadioGroup實現(xiàn)自動換行的方法,文章內容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

目前成都創(chuàng)新互聯(lián)已為成百上千的企業(yè)提供了網(wǎng)站建設、域名、網(wǎng)絡空間、綿陽服務器托管、企業(yè)網(wǎng)站設計、甘谷網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

具體內容如下:

public class FlowRadioGroup extends RadioGroup {

    private static final String TAG = "MyRadioGroup";

    public FlowRadioGroup(Context context) {

        super(context);

    }

    public FlowRadioGroup(Context context, AttributeSet attrs) {

        super(context, attrs);

    }

    @Override

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int widthSize = MeasureSpec.getSize(widthMeasureSpec);

        int widthMode = MeasureSpec.getMode(widthMeasureSpec);

        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        //調用ViewGroup的方法,測量子view

        measureChildren(widthMeasureSpec, heightMeasureSpec);

        //較大的寬

        int maxWidth = 0;

        //累計的高

        int totalHeight = 0;

        //當前這一行的累計行寬

        int lineWidth = 0;

        //當前這行的較大行高

        int maxLineHeight = 0;

        //用于記錄換行前的行寬和行高

        int oldHeight;

        int oldWidth;

        int count = getChildCount();

        //假設 widthMode和heightMode都是AT_MOST

        for (int i = 0; i< count; i++) {

            View child = getChildAt(i);

            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();

            oldHeight = maxLineHeight;

            //當前較大寬度

            oldWidth = maxWidth;

            int deltaX = child.getMeasuredWidth() + params.leftMargin + params.rightMargin;

            if (lineWidth + deltaX + getPaddingLeft() + getPaddingRight()> widthSize) {//如果折行,height增加

                //和目前較大的寬度比較,得到最寬。不能加上當前的child的寬,所以用的是oldWidth

                maxWidth = Math.max(lineWidth, oldWidth);

                //重置寬度

                lineWidth = deltaX;

                //累加高度

                totalHeight += oldHeight;

                //重置行高,當前這個View,屬于下一行,因此當前較大行高為這個child的高度加上margin

                maxLineHeight = child.getMeasuredHeight() + params.topMargin + params.bottomMargin;

                Log.v(TAG, "maxHeight:" + totalHeight + "---" + "maxWidth:" + maxWidth);

            } else {

                //不換行,累加寬度

                lineWidth += deltaX;

                //不換行,計算行高

                int deltaY = child.getMeasuredHeight() + params.topMargin + params.bottomMargin;

                maxLineHeight = Math.max(maxLineHeight, deltaY);

            }

            if (i == count - 1) {

                //前面沒有加上下一行的搞,如果是最后一行,還要再疊加上最后一行的高的值

                totalHeight += maxLineHeight;

                //計算最后一行和前面的最寬的一行比較

                maxWidth = Math.max(lineWidth, oldWidth);

            }

        }

        //加上當前容器的padding值

        maxWidth += getPaddingLeft() + getPaddingRight();

        totalHeight += getPaddingTop() + getPaddingBottom();

        setMeasuredDimension(widthMode == MeasureSpec.EXACTLY ? widthSize : maxWidth,

                heightMode == MeasureSpec.EXACTLY ? heightSize : totalHeight);

    }

    @Override

    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        int count = getChildCount();

        //pre為前面所有的child的相加后的位置

        int preLeft = getPaddingLeft();

        int preTop = getPaddingTop();

        //記錄每一行的高值

        int maxHeight = 0;

        for (int i = 0; i< count; i++) {

            View child = getChildAt(i);

            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();

            //r-l為當前容器的寬度。如果子view的累積寬度大于容器寬度,就換行。

            if (preLeft + params.leftMargin + child.getMeasuredWidth() + params.rightMargin + getPaddingRight()> (r - l)) {

                //重置

                preLeft = getPaddingLeft();

                //要選擇child的height較大的作為設置

                preTop = preTop + maxHeight;

                maxHeight = getChildAt(i).getMeasuredHeight() + params.topMargin + params.bottomMargin;

            } else { //不換行,計算較大高度

                maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + params.topMargin + params.bottomMargin);

            }

            //left坐標

            int left = preLeft + params.leftMargin;

            //top坐標

            int top = preTop + params.topMargin;

            int right = left + child.getMeasuredWidth();

            int bottom = top + child.getMeasuredHeight();

            //為子view布局

            child.layout(left, top, right, bottom);

            //計算布局結束后,preLeft的值

            preLeft += params.leftMargin + child.getMeasuredWidth() + params.rightMargin;

        }

    }

}

上述就是小編為大家分享的Android RadioGroup實現(xiàn)自動換行的方法了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


文章題目:AndroidRadioGroup實現(xiàn)自動換行的方法-創(chuàng)新互聯(lián)
轉載注明:http://www.xueling.net.cn/article/csojhs.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 老司机久草 | 作爱视频在线免费观看 | 色哟哟日韩精品 | 中文字幕V亚洲日本在线 | aaaa日韩| 日韩伦理亚洲一区 | 黄色av大全| 中国女人一级片 | 九九免费在线视频 | 91精品啪啪| 亚洲九九夜夜 | 日韩欧美中文字幕视频 | 精品欧美乱码久久久久久1区2区 | 成人午夜在线播放 | 精品无码黑人又粗又大又长 | 天天操夜夜操国产精品 | 亚洲精品天堂成人片AV在线播放 | 成年美女黄网站色大免费视频 | 国产在线无码精品无码 | 少妇伦子伦精品无码 | 国产精品久久久久久久久免费看 | 久久九九有精品国产 | 人妻激情偷乱一区二区三区 | 女子初尝黑人巨嗷嗷叫 | 久久亚洲精品无码AV红樱桃 | 无码人妻精品中文字幕不卡 | 成年人免费小视频 | 久久久麻豆精品 | 成人午夜视频在线 | 亚洲天堂久久久 | 亚洲AV永久无码天堂影院黑人 | 永久免费a片在线观看全网站 | 久久精品娱乐亚洲领先 | 亚洲最大一级无码av网站 | 综合图区亚洲欧美另类图片 | 色欲蜜桃AV无码中文字幕 | 免费AV片在线观看蜜芽TV | 2020国产乱轮免费片 | 西西人体大胆扒开下部337卩 | 国产亚洲精品久久久久久豆腐 | 亚洲第一页在线视频 |