Skip to content

Commit

Permalink
[ +] MiniFenShiView 增加一个 enableGradientBottom 属性,控制渐变是否显隐
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsanning committed Jul 4, 2020
1 parent 5d9f9d0 commit 7c715fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_mini_fen_shi.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ysn="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fillViewport="true"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

Expand Down Expand Up @@ -104,7 +105,8 @@
android:layout_width="100dp"
android:layout_height="65dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
android:layout_marginBottom="5dp"
ysn:enableGradientBottom="false" />

<TextView
android:id="@+id/mini_fen_shi_activity_code4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MiniFenShiConfig {
public int downColor;
public int equalColor;
public int gradientBottomColor;
public boolean enableGradientBottom;
public int strokeWidth;
public int areaAlpha;
public PathEffect pathEffect;
Expand All @@ -57,7 +58,9 @@ public void initAttr(Context context, AttributeSet attrs) {
upColor = typedArray.getColor(R.styleable.MiniFenShiView_upColor, ResUtils.getColor(context, R.color.mini_fen_shi_up));
downColor = typedArray.getColor(R.styleable.MiniFenShiView_downColor, ResUtils.getColor(context, R.color.mini_fen_shi_down));
equalColor = typedArray.getColor(R.styleable.MiniFenShiView_equalColor, ResUtils.getColor(context, R.color.mini_fen_shi_equal));

gradientBottomColor = typedArray.getColor(R.styleable.MiniFenShiView_gradientBottomColor, ResUtils.getColor(context, R.color.mini_fen_shi_gradient_bottom));
enableGradientBottom = typedArray.getBoolean(R.styleable.MiniFenShiView_enableGradientBottom, true);

strokeWidth = typedArray.getDimensionPixelSize(R.styleable.MiniFenShiView_strokeWidth, 4);
areaAlpha = typedArray.getDimensionPixelSize(R.styleable.MiniFenShiView_areaAlpha, 150);
Expand Down
28 changes: 17 additions & 11 deletions stock/src/main/java/ysn/com/stock/view/MiniFenShiView.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ protected void onChildDraw(Canvas canvas) {
return;
}

//渐变效果
LinearGradient gradient = new LinearGradient(
0,
getTopTableMaxY(),
0,
getTopTableMinY(),
config.gradientBottomColor,
config.currentColor,
Shader.TileMode.CLAMP);
config.priceAreaPaint.setShader(gradient);
if (config.enableGradientBottom) {
//渐变效果
LinearGradient gradient = new LinearGradient(
0,
getTopTableMaxY(),
0,
getTopTableMinY(),
config.gradientBottomColor,
config.currentColor,
Shader.TileMode.CLAMP);
config.priceAreaPaint.setShader(gradient);
}

config.pricePaint.setColor(config.currentColor);
config.dottedLinePaint.setColor(config.currentColor);

Expand Down Expand Up @@ -118,7 +121,10 @@ private void drawPriceLine(Canvas canvas) {
config.pricePath.lineTo(getX(dataManager.getLastPricePosition()), topTableMaxY);
config.pricePath.lineTo(getCircleX(), topTableMaxY);
config.pricePath.close();
canvas.drawPath(config.pricePath, config.priceAreaPaint);

if (config.enableGradientBottom) {
canvas.drawPath(config.pricePath, config.priceAreaPaint);
}

config.pricePath.reset();
}
Expand Down
3 changes: 3 additions & 0 deletions stock/src/main/res/values/attrs_mini_fen_shi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
<attr name="downColor" format="color" />
<!-- 不涨不跌颜色-->
<attr name="equalColor" format="color" />

<!-- 渐变底部颜色-->
<attr name="gradientBottomColor" format="color" />
<!-- 是否启用底部渐变-->
<attr name="enableGradientBottom" format="boolean" />

<!-- 实线宽-->
<attr name="strokeWidth" format="dimension" />
Expand Down

0 comments on commit 7c715fa

Please sign in to comment.