Commit f9338d08 authored by xwenliang's avatar xwenliang

style: android splitters color

parent e707f315
...@@ -4,6 +4,7 @@ import android.content.Context; ...@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Handler; import android.os.Handler;
import android.util.AttributeSet; import android.util.AttributeSet;
...@@ -17,6 +18,11 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -17,6 +18,11 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/**
* Edited by shexiaoheng on 2016/10/20
* 1. Added method getY
* 2. Changed line color 0xffc5c5c5 -> 0xffb8bbc2
*/
public class LoopView extends View { public class LoopView extends View {
private float scaleX = 1.05F; private float scaleX = 1.05F;
...@@ -106,7 +112,8 @@ public class LoopView extends View { ...@@ -106,7 +112,8 @@ public class LoopView extends View {
textSize = 0; textSize = 0;
colorGray = 0xffafafaf; colorGray = 0xffafafaf;
colorBlack = 0xff313131; colorBlack = 0xff313131;
colorLightGray = 0xffc5c5c5; colorLightGray = 0xffb8bbc2;
// colorLightGray = 0xffc5c5c5;
totalScrollY = 0; totalScrollY = 0;
initPosition = -1; initPosition = -1;
...@@ -338,32 +345,32 @@ public class LoopView extends View { ...@@ -338,32 +345,32 @@ public class LoopView extends View {
// 条目经过第一条线 // 条目经过第一条线
canvas.save(); canvas.save();
canvas.clipRect(0, 0, getWidth(), firstLineY - translateY); canvas.clipRect(0, 0, getWidth(), firstLineY - translateY);
canvas.drawText(text, getX(text, paintOuterText), maxTextHeight, paintOuterText); canvas.drawText(text, getX(text, paintOuterText), getY(paintOuterText), paintOuterText);
canvas.restore(); canvas.restore();
canvas.save(); canvas.save();
canvas.clipRect(0, firstLineY - translateY, getWidth(), (int) (itemHeight)); canvas.clipRect(0, firstLineY - translateY, getWidth(), (int) (itemHeight));
canvas.drawText(text, getX(text, paintCenterText), maxTextHeight, paintCenterText); canvas.drawText(text, getX(text, paintCenterText), getY(paintCenterText), paintCenterText);
canvas.restore(); canvas.restore();
} else if (translateY <= secondLineY && maxTextHeight + translateY >= secondLineY) { } else if (translateY <= secondLineY && maxTextHeight + translateY >= secondLineY) {
// 条目经过第二条线 // 条目经过第二条线
canvas.save(); canvas.save();
canvas.clipRect(0, 0, getWidth(), secondLineY - translateY); canvas.clipRect(0, 0, getWidth(), secondLineY - translateY);
canvas.drawText(text, getX(text, paintCenterText), maxTextHeight, paintCenterText); canvas.drawText(text, getX(text, paintCenterText), getY(paintCenterText), paintCenterText);
canvas.restore(); canvas.restore();
canvas.save(); canvas.save();
canvas.clipRect(0, secondLineY - translateY, getWidth(), (int) (itemHeight)); canvas.clipRect(0, secondLineY - translateY, getWidth(), (int) (itemHeight));
canvas.drawText(text, getX(text, paintOuterText), maxTextHeight, paintOuterText); canvas.drawText(text, getX(text, paintOuterText), getY(paintOuterText), paintOuterText);
canvas.restore(); canvas.restore();
} else if (translateY >= firstLineY && maxTextHeight + translateY <= secondLineY) { } else if (translateY >= firstLineY && maxTextHeight + translateY <= secondLineY) {
// 中间条目 // 中间条目
canvas.clipRect(0, 0, getWidth(), (int) (itemHeight)); canvas.clipRect(0, 0, getWidth(), (int) (itemHeight));
canvas.drawText(text, getX(text, paintCenterText), maxTextHeight, paintCenterText); canvas.drawText(text, getX(text, paintCenterText), getY(paintCenterText), paintCenterText);
selectedItem = text; selectedItem = text;
selectedIndex = items.indexOf(text); selectedIndex = items.indexOf(text);
} else { } else {
// 其他条目 // 其他条目
canvas.clipRect(0, 0, getWidth(), (int) (itemHeight)); canvas.clipRect(0, 0, getWidth(), (int) (itemHeight));
canvas.drawText(text, getX(text, paintOuterText), maxTextHeight, paintOuterText); canvas.drawText(text, getX(text, paintOuterText), getY(paintOuterText), paintOuterText);
} }
canvas.restore(); canvas.restore();
} }
...@@ -376,6 +383,18 @@ public class LoopView extends View { ...@@ -376,6 +383,18 @@ public class LoopView extends View {
return (getWidth() - tempRect.width() * scaleX) / 2; return (getWidth() - tempRect.width() * scaleX) / 2;
} }
/**
* Added by shexiaoheng
* 让字体垂直方向居中
* */
private float getY(Paint paint) {
Rect rect = new Rect(0, 0, getWidth(), maxTextHeight);
RectF bounds = new RectF(rect);
bounds.bottom = paint.descent() - paint.ascent();
bounds.top += (rect.height() - bounds.bottom) / 2.0f;
return bounds.top - paint.ascent();
}
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
......
{ {
"name": "react-native-picker", "name": "react-native-picker",
"version": "4.0.6", "version": "4.0.7",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment