Skip to content

Conversation

@SeaSoon
Copy link

@SeaSoon SeaSoon commented Mar 18, 2015

首先编码改成了u8,然后将pickview的一些属性暴露出来,例如最大最小文字,颜色,透明度等暴露成attrs中的属性值来让用户自定义,接着解决了width和height设置为Warp_content的时候pickerview全屏问题,设置了默认值,同时兼容fill_parent和自己设置大小。改动不算太大,更加自由了一些。

首先编码改成了u8,然后将pickview的一些属性暴露出来,例如最大最小文字,颜色,透明度等暴露成attrs中的属性值来让用户自定义,接着解决了width和height设置为Warp_content的时候pickerview全屏问题,设置了默认值,同时兼容fill_parent和自己设置大小。改动不算太大,更加自由了一些。
@gzu-liyujiang
Copy link

@SeaSoon 的Pull Requests的init()方法中获取XML里设置的width和height不太靠谱,只针对了dp、dip,无法应对px。可以考虑以下方式:

        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        int width = layoutParams.width;
        int height = layoutParams.height;

        final float scale = context.getResources().getDisplayMetrics().density;
        if (width == ViewGroup.LayoutParams.WRAP_CONTENT) {
            if (mMaxTextSize == 0) {
                mViewHeight = (int) (160 * scale + 0.5f);
                mViewWidth = (int) (80 * scale + 0.5f);
            } else {
                mViewHeight = (int) mMaxTextSize * 4;
                mViewWidth = (int) mMaxTextSize * 2;
            }
            useDefault = true;
        } else if (width == ViewGroup.LayoutParams.MATCH_PARENT) {
            useDefault = false;
        } else {
            mViewHeight = (int) (height * scale + 0.5f);
            mViewWidth = (int) (width * scale + 0.5f);
            useDefault = true;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants