当前位置: 首页>>代码示例>>Java>>正文


Java LinearGradient类代码示例

本文整理汇总了Java中android.graphics.LinearGradient的典型用法代码示例。如果您正苦于以下问题:Java LinearGradient类的具体用法?Java LinearGradient怎么用?Java LinearGradient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LinearGradient类属于android.graphics包,在下文中一共展示了LinearGradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: HeaderShadowDecoration

import android.graphics.LinearGradient; //导入依赖的package包/类
public HeaderShadowDecoration(View view, boolean scrollsHorizontally, float parallax, float shadowSize, int columns) {
    mView = view;
    mHorizontal = scrollsHorizontally;
    mParallax = parallax;
    mShadowSize = shadowSize;
    mColumns = columns;

    if (mShadowSize > 0) {
        mShadowPaint = new Paint();
        mShadowPaint.setShader(mHorizontal ?
                new LinearGradient(mShadowSize, 0, 0, 0,
                        new int[]{Color.argb(55, 0, 0, 0), Color.argb(55, 0, 0, 0), Color.argb(3, 0, 0, 0)},
                        new float[]{0f, .5f, 1f},
                        Shader.TileMode.CLAMP) :
                new LinearGradient(0, mShadowSize, 0, 0,
                        new int[]{Color.argb(55, 0, 0, 0), Color.argb(55, 0, 0, 0), Color.argb(3, 0, 0, 0)},
                        new float[]{0f, .5f, 1f},
                        Shader.TileMode.CLAMP));
    } else {
        mShadowPaint = null;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:HeaderShadowDecoration.java

示例2: surfaceChanged

import android.graphics.LinearGradient; //导入依赖的package包/类
/**
 * SurfaceHolder.Callback function. This is called every time the dimension changes
 * (and after the SurfaceView is created).
 *
 * @param holder	reference to the surface holder
 * @param format
 * @param width		current width of the surface view
 * @param height	current height of the surface view
 */
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
	if(this.width != width || this.height != height) {
		this.width = width;
		this.height = height;

		// Recreate the shaders:
		this.fftPaint.setShader(new LinearGradient(0, 0, 0, getFftHeight(), Color.WHITE, Color.parseColor(fftColor), Shader.TileMode.MIRROR));

		// Recreate the waterfall bitmaps:
		this.createWaterfallLineBitmaps();

		// Fix the text size of the text paint objects:
		this.setFontSize(fontSize);
	}
}
 
开发者ID:takyonxxx,项目名称:AndroidSdrRtlTuner,代码行数:26,代码来源:AnalyzerSurface.java

示例3: onSizeChanged

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override
   protected void onSizeChanged(int w, int h, int oldw, int oldh)
   {
super.onSizeChanged(w, h, oldw, oldh);
if (mViewWidth == 0)
{
    mViewWidth = getMeasuredWidth();
    if (mViewWidth > 0)
    {
	mPaint = getPaint();
	mLinearGradient = new LinearGradient(-mViewWidth, 0, 0, 0,new int[] { 0x45B3B5, 0x45B3B5, 0x33ffffff },new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP);
	mPaint.setShader(mLinearGradient);
	mGradientMatrix = new Matrix();
    }
}
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:17,代码来源:nicoTextView.java

示例4: init

import android.graphics.LinearGradient; //导入依赖的package包/类
private void init() {
   setLayerType(LAYER_TYPE_SOFTWARE,null);
    bgpaint = new Paint();
    bgpaint.setColor(backColor);
    bgpaint.setAntiAlias(true);

    proPaint = new Paint();
    proPaint.setColor(progressColor);
    LinearGradient linearGradient = new LinearGradient(0, 0, width, height, progressColor, progressendcolor, Shader.TileMode.CLAMP);
    proPaint.setShader(linearGradient);
    proPaint.setAntiAlias(true);

    textPaint = new Paint();
    textPaint.setColor(textColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(textsize);
    textbaseline = getFontstart(textPaint);
    rectbg = new RectF();
    rectprogress = new RectF();
}
 
开发者ID:While1true,项目名称:JSSample,代码行数:21,代码来源:SProgress.java

示例5: onSizeChanged

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);

  viewWidth = w;
  viewHeight = h;

  centerX           = viewWidth / 2;
  colorPickerRadius = (viewWidth / 2) - borderWidth;

  colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));

  LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
  paint.setShader(gradient);

  if (bitmap != null) {
    bitmap.recycle();
  }

  bitmap       = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
  bitmapCanvas = new Canvas(bitmap);

  resetToDefault();
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:25,代码来源:VerticalSlideColorPicker.java

示例6: onSurfaceTextureAvailable

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override   // will be called on UI thread
public void onSurfaceTextureAvailable(SurfaceTexture st, int width, int height) {
    Log.d(TAG, "onSurfaceTextureAvailable(" + width + "x" + height + ")");
    mWidth = width;
    mHeight = height;
    mMaxAmpl = height / 2;
    mPaints.get(0).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#CA67B7"), Color.parseColor("#C081C1"), Shader.TileMode.MIRROR));
    mPaints.get(0).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
    mPaints.get(1).setColor(Color.parseColor("#D5E3FA"));
    mPaints.get(1).setStrokeWidth(ScreenUtils.dp2px(getContext(), 2));
    mPaints.get(2).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
    mPaints.get(3).setStrokeWidth(ScreenUtils.dp2px(getContext(), 1));
    mPaints.get(2).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
    mPaints.get(3).setShader(new LinearGradient(0, 0, mWidth, mHeight, Color.parseColor("#E67EA5"), Color.parseColor("#7F7AE1"), Shader.TileMode.MIRROR));
    synchronized (mLock) {
        mSurfaceTexture = st;
        mLock.notify();
    }
}
 
开发者ID:TheAwesomeCompany,项目名称:WaveAudioVizualization,代码行数:20,代码来源:VoiceWaveViewTV.java

示例7: drawColorSquare

import android.graphics.LinearGradient; //导入依赖的package包/类
private void drawColorSquare(Canvas canvas) {
    int pureColor, brightColor, darkColor, transparentColor;

    // pureColor
    mHSV[0] = mColorHSV[0];
    mHSV[1] = 1; mHSV[2] = 1;
    pureColor = Color.HSVToColor(mHSV);
    // brightColor
    mHSV[1] = 0; mHSV[2] = 1;
    brightColor = Color.HSVToColor(mHSV);
    // darkColor
    mHSV[1] = 1; mHSV[2] = 0;
    darkColor = Color.HSVToColor(255, mHSV);
    // alphaColor
    mHSV[1] = 0; mHSV[2] = 0;
    transparentColor = Color.HSVToColor(0, mHSV);

    // drawn without compose shader, but looks worse
    Shader gradient1 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.right, mSquareRect.top, brightColor, pureColor, TileMode.CLAMP);
    Shader gradient2 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.left, mSquareRect.bottom, transparentColor, darkColor, TileMode.CLAMP);

    mColorPaint.setShader(gradient1);
    canvas.drawRect(mSquareRect, mColorPaint);
    mColorPaint.setShader(gradient2);
    canvas.drawRect(mSquareRect, mColorPaint);
}
 
开发者ID:dftec-es,项目名称:planetcon,代码行数:27,代码来源:ColorPicker.java

示例8: onSizeChanged

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
    super.onSizeChanged(w, h, oldW, oldH);
    if (mViewWidth == 0) {
        mViewWidth = getMeasuredWidth();
        if (mViewWidth > 0) {
            Paint paint = getPaint();
            String text = getText().toString();
            mTextWidth = paint.measureText(text);
            int size = (int)paint.measureText(text);
            int startX = (mViewWidth - size) / 2;
            mLinearGradient = new LinearGradient(startX + 1, 0, 0, 0,
                    new int[] { 0x90ffffff, 0xffffffff, 0x90ffffff },
                    new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP); //边缘融合
            paint.setShader(mLinearGradient);
            mGradientMatrix = new Matrix();
        }
    }
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:20,代码来源:GradientShaderTextView.java

示例9: FadingShadow

import android.graphics.LinearGradient; //导入依赖的package包/类
/**
 * @param shadowColor The color of the shadow, e.g. 0x11000000.
 */
public FadingShadow(int shadowColor) {
    final int n = SMOOTH_ALGORITHM_INTERPOLATION_POINTS_NUM;
    float[] positions = new float[n];
    int[] colors = new int[n];
    int transparentShadowColor = shadowColor & 0x00FFFFFF;
    int shadowAlpha = Color.alpha(shadowColor);

    // Piece-wise linear interpolation of the smooth cubic function below.
    for (int i = 0; i < n; ++i) {
        float x = (float) i / (n - 1);
        // Polynomial computation by Estrin's scheme.
        float value = (1.0f - 2.2f * x) + (1.8f - 0.6f * x) * (x * x);

        positions[i] = x;
        colors[i] = (Math.round(shadowAlpha * value) << 24) | transparentShadowColor;
    }

    mShadowShader = new LinearGradient(0, 0, 0, 1, colors, positions, Shader.TileMode.CLAMP);

}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:FadingShadow.java

示例10: setColor

import android.graphics.LinearGradient; //导入依赖的package包/类
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if (mOrientation == ORIENTATION_HORIZONTAL) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	} else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}

	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1,
			new int[] { Color.WHITE, color }, null, Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
	calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if (mPicker.hasValueBar())
			mPicker.changeValueBarColor(mColor);
		else if (mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:33,代码来源:SaturationBar.java

示例11: buildShadowCorners

import android.graphics.LinearGradient; //导入依赖的package包/类
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
    this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:RoundRectDrawableWithShadow.java

示例12: generateElements

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override
public void generateElements() {
    cloudShader = new LinearGradient(getWidth() / 2, 0, getWidth() / 2, getHeight() * 0.618f, 0xFFFFFFFF,
            0x00FFFFFF, Shader.TileMode.CLAMP);
    final float textSize = getHeight() / 32f;
    fanPath.reset();
    final float fanSize = textSize * 0.2f;// 风扇底部半圆的半径
    final float fanHeight = textSize * 2f;
    final float fanCenterOffsetY = fanSize * 1.6f;
    fanPath.addArc(new RectF(-fanSize, -fanSize - fanCenterOffsetY, fanSize, fanSize - fanCenterOffsetY), 0,
            180);
    fanPath.quadTo(-fanSize * 1f, -fanHeight * 0.5f - fanCenterOffsetY, 0, -fanHeight - fanCenterOffsetY);
    fanPath.quadTo(fanSize * 1f, -fanHeight * 0.5f - fanCenterOffsetY, fanSize, -fanCenterOffsetY);
    fanPath.close();

    fanPillarPath.reset();
    final float fanPillarSize = textSize * 0.20f;// 柱子的宽度
    fanPillarPath.moveTo(0, 0);
    fanPillerHeight = textSize * 4f;// 柱子的高度
    fanPillarPath.lineTo(2, 0);
    fanPillarPath.lineTo(fanPillarSize, fanPillerHeight);
    fanPillarPath.lineTo(-fanPillarSize, fanPillerHeight);
    fanPillarPath.lineTo(-2, 0);
    fanPillarPath.close();
}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:26,代码来源:OvercastType.java

示例13: setColor

import android.graphics.LinearGradient; //导入依赖的package包/类
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if(mOrientation == ORIENTATION_HORIZONTAL) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	}
	else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}
	
	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0,
			x1, y1, new int[] {
					color, Color.BLACK }, null, Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
	calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if(mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:33,代码来源:ValueBar.java

示例14: getSourceMaskBitmap

import android.graphics.LinearGradient; //导入依赖的package包/类
private Bitmap getSourceMaskBitmap() {
    if (sourceMaskBitmap != null) {
        return sourceMaskBitmap;
    }

    int width = maskRect.width();
    int height = getHeight();

    final int edgeColor = reduceColorAlphaValueToZero(shimmerColor);
    LinearGradient gradient = new LinearGradient(
            -maskRect.left, 0,
            width + maskRect.left, 0,
            new int[]{edgeColor, shimmerColor, shimmerColor, edgeColor},
            getGradientColorDistribution(),
            Shader.TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(gradient);

    sourceMaskBitmap = createBitmap(width, height);
    Canvas canvas = new Canvas(sourceMaskBitmap);
    canvas.rotate(shimmerAngle, width / 2, height / 2);
    canvas.drawRect(-maskRect.left, maskRect.top, width + maskRect.left, maskRect.bottom, paint);

    return sourceMaskBitmap;
}
 
开发者ID:team-supercharge,项目名称:ShimmerLayout,代码行数:26,代码来源:ShimmerLayout.java

示例15: draw

import android.graphics.LinearGradient; //导入依赖的package包/类
@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();

    Paint huePaint = new Paint();
    huePaint.setShader(new LinearGradient(0, 0, b.width(), 0,
            new int[]{
                    0xFFFF0000,
                    0xFFFFFF00,
                    0xFF00FF00,
                    0xFF00FFFF,
                    0xFF0000FF,
                    0xFFFF00FF,
                    0xFFFF0000
            },
            null,
            Shader.TileMode.REPEAT)
    );
    canvas.drawRect(b, huePaint);
}
 
开发者ID:google,项目名称:spline,代码行数:21,代码来源:HueDrawable.java


注:本文中的android.graphics.LinearGradient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。