CountdownView
CountdownView copied to clipboard
发现一个问题,使用背景,而且不展示边框的时候,mSuffix显示效果会右移
如题, 经过查看我发现这个问题的确是有的 在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);
app:isShowTimeBgBorder="true" app:timeBgBorderColor="@color/transparent" 如果不想显示边框,文字并且居中,可以设置边框颜色为透明即可
app:isShowTimeBgBorder="true" app:timeBgBorderColor="@color/transparent" 如果不想显示边框,文字并且居中,可以设置边框颜色为透明即可 麻烦看下这个问题呢? https://github.com/iwgang/CountdownView/issues/132