Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现一个问题,使用背景,而且不展示边框的时候,mSuffix显示效果会右移 #118

Open
zzh1026 opened this issue Dec 10, 2018 · 2 comments

Comments

@zzh1026
Copy link

zzh1026 commented Dec 10, 2018

如题, 经过查看我发现这个问题的确是有的
在BackgroundCountdown#initStyleAttr(Context context, TypedArray ta)方法中第 51行和54行有这样的代码

mTimeBgBorderSize = ta.getDimension(R.styleable.CountdownView_timeBgBorderSize, Utils.dp2px(context, DEFAULT_TIME_BG_BORDER_SIZE));
isShowTimeBgBorder = ta.getBoolean(R.styleable.CountdownView_isShowTimeBgBorder, false);

但是 DEFAULT_TIME_BG_BORDER_SIZE 默认为 1dp
在 onDraw(Canvas canvas) 方法中各个Suffix的处理中,有:

if (mSuffixDayTextWidth > 0) {
         // draw day suffix
         canvas.drawText(mSuffixDay, mLeftPaddingSize + mDayTimeBgWidth + mSuffixDayLeftMargin + (mTimeBgBorderSize * 2), mSuffixDayTextBaseline, mSuffixTextPaint);
}

这个 mTimeBgBorderSize * 2 造成了 mSuffixDay 右移的情况, 因为此时并不显示TimeBgBorder,但是却计算了 mTimeBgBorderSize 的值,因此建议在 initStyleAttr(Context context, TypedArray ta) 方法中54行的:

isShowTimeBgBorder = ta.getBoolean(R.styleable.CountdownView_isShowTimeBgBorder, false);

下面添加:

if (!isShowTimeBgBorder) {
        mTimeBgBorderSize = 0;
 }

来处理,即当不显示背景边框的时候,这个边框的大小为0,不接入计算.

ps: demo中的DynamicShowActivity显示没有问题是因为其在第471行左右对border进行了设置:

((CheckBox) findViewById(R.id.cb_bgBorder)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                btnModBgBorderColor.setEnabled(isChecked);
                btnBgBorderSizePlus.setEnabled(isChecked);
                btnBgBorderSizeSubtract.setEnabled(isChecked);
                btnBgBorderRadiusPlus.setEnabled(isChecked);
                btnBgBorderRadiusSubtract.setEnabled(isChecked);

                DynamicConfig.Builder dynamicConfigBuilder = new DynamicConfig.Builder();
                dynamicConfigBuilder.setBackgroundInfo(new DynamicConfig.BackgroundInfo().setShowTimeBgBorder(isChecked));
                mCvCountdownViewTestHasBg.dynamicShow(dynamicConfigBuilder.build());
            }
        });
((CheckBox) findViewById(R.id.cb_bgBorder)).setChecked(false);
@917163738
Copy link

app:isShowTimeBgBorder="true"
app:timeBgBorderColor="@color/transparent"
如果不想显示边框,文字并且居中,可以设置边框颜色为透明即可

@ysj40540
Copy link

ysj40540 commented Aug 9, 2022

app:isShowTimeBgBorder="true" app:timeBgBorderColor="@color/transparent" 如果不想显示边框,文字并且居中,可以设置边框颜色为透明即可
麻烦看下这个问题呢?
#132

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

No branches or pull requests

3 participants