Skip to content

Commit

Permalink
选择器条目默认显示由3条改为5条,并修改条目文字的内边距
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Dec 21, 2016
1 parent 37c5b0c commit aaed6c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ com.android.build.gradle.overridePathCheck=true
#android.useDeprecatedNdk=true

#下面定义一些常量供gradle脚本使用
VERSION_NAME=1.3.2
VERSION_CODE=132
VERSION_NAME=1.3.3
VERSION_CODE=133
COMPILE_SDK_VERSION=23
MIN_SDK_VERSION=11
#安卓6.0开始(API23+),需要动态申请权限
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ public void setLineConfig(@Nullable WheelView.LineConfig config) {
}

/**
* 设置选项偏移量,默认为1,范围为1-4。
* 1显示三条、2显示5条、3显示7条、4显示9条
* 使用最长的分割线,多级选择器时可以实现连线效果
*
* @see #setLineConfig(WheelView.LineConfig)
*/
public void useMaxRatioLine() {
lineConfig = new WheelView.LineConfig(0);
}

/**
* 设置选项偏移量,可用来要设置显示的条目数,范围为1-3。
* 1显示3条、2显示5条、3显示7条
*/
public void setOffset(@IntRange(from = 1, to = 3) int offset) {
this.offset = offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@
*/
public class WheelView extends ScrollView {
public static final int TEXT_SIZE = 20;
public static final int TEXT_PADDING = 10;
public static final int TEXT_PADDING_TOP_BOTTOM = 8;
public static final int TEXT_PADDING_LEFT_RIGHT = 15;
public static final int TEXT_COLOR_FOCUS = 0XFF0288CE;
public static final int TEXT_COLOR_NORMAL = 0XFFBBBBBB;
public static final int LINE_ALPHA = 150;
public static final int LINE_COLOR = 0XFF83CDE6;
public static final float LINE_THICK = 1f;
public static final int OFF_SET = 1;
private static final int DELAY = 30;
public static final int OFF_SET = 2;
private static final int DELAY = 50;
private static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT;
private static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;

private Context context;
private LinearLayout views;//容器
Expand Down Expand Up @@ -129,21 +132,22 @@ private void initData() {

private TextView createView(String item) {
TextView tv = new TextView(context);
tv.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tv.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
tv.setSingleLine(true);
tv.setEllipsize(TextUtils.TruncateAt.END);
tv.setText(item);
tv.setTextSize(textSize);
tv.setGravity(Gravity.CENTER);
int padding = ConvertUtils.toPx(context, TEXT_PADDING);
tv.setPadding(padding, padding, padding, padding);
int paddingTopBottom = ConvertUtils.toPx(context, TEXT_PADDING_TOP_BOTTOM);
int paddingLeftRight = ConvertUtils.toPx(context, TEXT_PADDING_LEFT_RIGHT);
tv.setPadding(paddingLeftRight, paddingTopBottom, paddingLeftRight, paddingTopBottom);
if (0 == itemHeight) {
int wSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int hSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
tv.measure(wSpec, hSpec);
itemHeight = tv.getMeasuredHeight();
LogUtils.verbose(this, "itemHeight: " + itemHeight);
views.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight * displayItemCount));
views.setLayoutParams(new LayoutParams(MATCH_PARENT, itemHeight * displayItemCount));
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams();
setLayoutParams(new LinearLayout.LayoutParams(lp.width, itemHeight * displayItemCount));
}
Expand Down

0 comments on commit aaed6c9

Please sign in to comment.