本文整理汇总了Java中android.graphics.drawable.GradientDrawable.setBounds方法的典型用法代码示例。如果您正苦于以下问题:Java GradientDrawable.setBounds方法的具体用法?Java GradientDrawable.setBounds怎么用?Java GradientDrawable.setBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setBounds方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCurrentPageShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
protected void drawCurrentPageShadow(Canvas canvas) {
canvas.save();
GradientDrawable shadow;
if (actiondownX > mScreenWidth >> 1) {
shadow = mBackShadowDrawableLR;
shadow.setBounds((int) (mScreenWidth + touch_down - 5), 0, (int) (mScreenWidth + touch_down + 5), mScreenHeight);
} else {
shadow = mBackShadowDrawableRL;
shadow.setBounds((int) (touch_down - 5), 0, (int) (touch_down + 5), mScreenHeight);
}
shadow.draw(canvas);
try {
canvas.restore();
} catch (Exception e) {
}
}
示例2: setVerValSlider
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* Create a linear gradient shader to show variations in value.
*/
private void setVerValSlider() {
float[] hsv = new float[3];
hsv[0] = mHSV[0];
hsv[1] = mHSV[1];
hsv[2] = 1;
int col = Color.HSVToColor(hsv);
int colors[] = new int[2];
colors[0] = col;
colors[1] = 0xFF000000;
GradientDrawable gradDraw = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
gradDraw.setDither(true);
gradDraw.setLevel(10000);
gradDraw.setBounds(0, 0, mSliderThicknessPx, mPaletteDimPx);
gradDraw.draw(mVerSliderCv);
}
示例3: addPulseRing
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void addPulseRing(LatLng latLng) {
GradientDrawable d = new GradientDrawable();
d.setShape(GradientDrawable.OVAL);
d.setSize(500, 500);
d.setColor(ContextCompat.getColor(this, R.color.pulse_color));
Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth()
, d.getIntrinsicHeight()
, Bitmap.Config.ARGB_8888);
// Convert the drawable to bitmap
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
// Radius of the circle
final int radius = 100;
// Add the circle to the map
circle = mMap.addGroundOverlay(new GroundOverlayOptions()
.position(latLng, 2 * radius).image(BitmapDescriptorFactory.fromBitmap(bitmap)));
}
示例4: drawPathAHorizontalShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 绘制A区域水平翻页阴影
* @param canvas
*/
private void drawPathAHorizontalShadow(Canvas canvas, Path pathA){
canvas.restore();
canvas.save();
canvas.clipPath(pathA, Region.Op.INTERSECT);
int maxShadowWidth = 30;//阴影矩形最大的宽度
int left = (int) (a.x - Math.min(maxShadowWidth,(rPathAShadowDis/2)));
int right = (int) (a.x);
int top = 0;
int bottom = viewHeight;
GradientDrawable gradientDrawable = drawableHorizontalLowerRight;
gradientDrawable.setBounds(left,top,right,bottom);
float mDegrees = (float) Math.toDegrees(Math.atan2(f.x-a.x,f.y-h.y));
canvas.rotate(mDegrees, a.x, a.y);
gradientDrawable.draw(canvas);
}
示例5: drawNextPageAreaAndShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
protected void drawNextPageAreaAndShadow(Canvas canvas) {
mPath1.reset();
mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
mPath1.lineTo(mCornerX, mCornerY);
mPath1.close();
mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x - mCornerX, mBezierControl2.y - mCornerY));
int leftx;
int rightx;
GradientDrawable mBackShadowDrawable;
if (mIsRTandLB) { //左下及右上
leftx = (int) (mBezierStart1.x);
rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
mBackShadowDrawable = mBackShadowDrawableLR;
} else {
leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
rightx = (int) mBezierStart1.x;
mBackShadowDrawable = mBackShadowDrawableRL;
}
canvas.save();
try {
canvas.clipPath(mPath0);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
} catch (Exception e) {
}
canvas.drawBitmap(mNextPageBitmap, 0, 0, null);
canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y,
rightx, (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
mBackShadowDrawable.draw(canvas);
canvas.restore();
}
示例6: drawNextPageAreaAndShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
mPath2.reset();
mPath2.moveTo(mBzStart1.x, mBzStart1.y);
mPath2.lineTo(mBzVertex1.x, mBzVertex1.y);
mPath2.lineTo(mBzVertex2.x, mBzVertex2.y);
mPath2.lineTo(mBzStart2.x, mBzStart2.y);
mPath2.lineTo(mCornerX, mCornerY);
mPath2.close();
mDegress = (float) Math.toDegrees(Math.atan2(mBzControl1.x
- mCornerX, mBzControl2.y - mCornerY));
int leftx;
int rightx;
GradientDrawable mBackShadowDrawable;
if (mIsRtOrLb) {
leftx = (int) (mBzStart1.x);
rightx = (int) (mBzStart1.x + mTouchCornerDis / 4);
mBackShadowDrawable = mBackDrawableLR;
} else {
leftx = (int) (mBzStart1.x - mTouchCornerDis / 4);
rightx = (int) mBzStart1.x;
mBackShadowDrawable = mBackDrawableRL;
}
canvas.save();
canvas.clipPath(mPath1);
canvas.clipPath(mPath2, Region.Op.INTERSECT);
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.rotate(mDegress, mBzStart1.x, mBzStart1.y);
// rotate就是旋转坐标,顺时针,默认原点旋转,可以指定旋转点,然后按照专选后的的坐标绘制,不会对之前的绘制有影响
// 其实可以这样看,我们先按原来坐标绘制出来东西,在把这个东西按照点来旋转角度,效果是一样的,我们的阴影绘制在(start.x - touchCornerDic / 4, mHeight, start.x, maxLen)矩形中
// 最后按照start点来旋转就可以变成原来当前页和下一页的交汇线下面的阴影 touchCornerDic / 4就是阴影的宽度
mBackShadowDrawable.setBounds(leftx, (int) mBzStart1.y, rightx,
(int) (mMaxLength + mBzStart1.y));
mBackShadowDrawable.draw(canvas);
canvas.restore();
}
示例7: drawNextPageAreaAndShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
mPath1.reset();
mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
mPath1.lineTo(mCornerX, mCornerY);
mPath1.close();
mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
- mCornerX, mBezierControl2.y - mCornerY));
int leftx;
int rightx;
GradientDrawable mBackShadowDrawable;
if (mIsRTandLB) { //左下及右上
leftx = (int) (mBezierStart1.x);
rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
mBackShadowDrawable = mBackShadowDrawableLR;
} else {
leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
rightx = (int) mBezierStart1.x;
mBackShadowDrawable = mBackShadowDrawableRL;
}
canvas.save();
try {
canvas.clipPath(mPath0);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
} catch (Exception e) {
}
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
(int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
mBackShadowDrawable.draw(canvas);
canvas.restore();
}
示例8: drawPathARightShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 绘制A区域右阴影
* @param canvas
*/
private void drawPathARightShadow(Canvas canvas, Path pathA){
canvas.restore();
canvas.save();
float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view对角线长度
int left = (int) h.x;
int right = (int) (h.x + viewDiagonalLength*10);//需要足够长的长度
int top;
int bottom;
GradientDrawable gradientDrawable;
if (style.equals(STYLE_TOP_RIGHT)) {
gradientDrawable = drawableRightTopRight;
top = (int) (h.y- rPathAShadowDis /2);
bottom = (int) h.y;
} else {
gradientDrawable = drawableRightLowerRight;
top = (int) h.y;
bottom = (int) (h.y+ rPathAShadowDis /2);
}
gradientDrawable.setBounds(left,top,right,bottom);
Path mPath = new Path();
mPath.moveTo(a.x- Math.max(rPathAShadowDis, lPathAShadowDis) /2,a.y);
// mPath.lineTo(i.x,i.y);
mPath.lineTo(h.x,h.y);
mPath.lineTo(a.x,a.y);
mPath.close();
canvas.clipPath(pathA);
canvas.clipPath(mPath, Region.Op.INTERSECT);
float mDegrees = (float) Math.toDegrees(Math.atan2(a.y-h.y, a.x-h.x));
canvas.rotate(mDegrees, h.x, h.y);
gradientDrawable.draw(canvas);
}
示例9: drawPathBShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 绘制B区域阴影,阴影左深右浅
* @param canvas
*/
private void drawPathBShadow(Canvas canvas){
int deepOffset = 0;//深色端的偏移值
int lightOffset = 0;//浅色端的偏移值
float aTof =(float) Math.hypot((a.x - f.x),(a.y - f.y));//a到f的距离
float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//对角线长度
int left;
int right;
int top = (int) c.y;
int bottom = (int) (viewDiagonalLength + c.y);
GradientDrawable gradientDrawable;
if(style.equals(STYLE_TOP_RIGHT)){//f点在右上角
//从左向右线性渐变
gradientDrawable = drawableBTopRight;
left = (int) (c.x - deepOffset);//c点位于左上角
right = (int) (c.x + aTof/4 + lightOffset);
}else {
//从右向左线性渐变
gradientDrawable = drawableBLowerRight;
left = (int) (c.x - aTof/4 - lightOffset);//c点位于左下角
right = (int) (c.x + deepOffset);
}
gradientDrawable.setBounds(left,top,right,bottom);//设置阴影矩形
float rotateDegrees = (float) Math.toDegrees(Math.atan2(e.x- f.x, h.y - f.y));//旋转角度
canvas.rotate(rotateDegrees, c.x, c.y);//以c为中心点旋转
gradientDrawable.draw(canvas);
}
示例10: drawPathCShadow
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 绘制C区域阴影,阴影左浅右深
* @param canvas
*/
private void drawPathCShadow(Canvas canvas){
int deepOffset = 1;//深色端的偏移值
int lightOffset = -30;//浅色端的偏移值
float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view对角线长度
int midpoint_ce = (int) (c.x + e.x) / 2;//ce中点
int midpoint_jh = (int) (j.y + h.y) / 2;//jh中点
float minDisToControlPoint = Math.min(Math.abs(midpoint_ce - e.x), Math.abs(midpoint_jh - h.y));//中点到控制点的最小值
int left;
int right;
int top = (int) c.y;
int bottom = (int) (viewDiagonalLength + c.y);
GradientDrawable gradientDrawable;
if (style.equals(STYLE_TOP_RIGHT)) {
gradientDrawable = drawableCTopRight;
left = (int) (c.x - lightOffset);
right = (int) (c.x + minDisToControlPoint + deepOffset);
} else {
gradientDrawable = drawableCLowerRight;
left = (int) (c.x - minDisToControlPoint - deepOffset);
right = (int) (c.x + lightOffset);
}
gradientDrawable.setBounds(left,top,right,bottom);
float mDegrees = (float) Math.toDegrees(Math.atan2(e.x- f.x, h.y - f.y));
canvas.rotate(mDegrees, c.x, c.y);
gradientDrawable.draw(canvas);
}
示例11: drawCurrentBackArea
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
@Override
protected void drawCurrentBackArea(Canvas canvas) {
int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
float f1 = Math.abs(i - mBezierControl1.x);
int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
float f2 = Math.abs(i1 - mBezierControl2.y);
float f3 = Math.min(f1, f2);
mPath1.reset();
mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
mPath1.lineTo(mTouch.x, mTouch.y);
mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
mPath1.close();
GradientDrawable mFolderShadowDrawable;
int left;
int right;
if (mIsRTandLB) {
left = (int) (mBezierStart1.x - 1);
right = (int) (mBezierStart1.x + f3 + 1);
mFolderShadowDrawable = mFolderShadowDrawableLR;
} else {
left = (int) (mBezierStart1.x - f3 - 1);
right = (int) (mBezierStart1.x + 1);
mFolderShadowDrawable = mFolderShadowDrawableRL;
}
canvas.save();
try {
canvas.clipPath(mPath0);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
} catch (Exception e) {
}
mPaint.setColorFilter(mColorMatrixFilter);
float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
mBezierControl2.y - mCornerY);
float f8 = (mCornerX - mBezierControl1.x) / dis;
float f9 = (mBezierControl2.y - mCornerY) / dis;
mMatrixArray[0] = 1 - 2 * f9 * f9;
mMatrixArray[1] = 2 * f8 * f9;
mMatrixArray[3] = mMatrixArray[1];
mMatrixArray[4] = 1 - 2 * f8 * f8;
mMatrix.reset();
mMatrix.setValues(mMatrixArray);
mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
canvas.drawBitmap(mCurPageBitmap, mMatrix, mPaint);
// canvas.drawBitmap(bitmap, mMatrix, null);
mPaint.setColorFilter(null);
canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
(int) (mBezierStart1.y + mMaxLength));
mFolderShadowDrawable.draw(canvas);
canvas.restore();
}
示例12: drawCurrentBackArea
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* 绘制翻起页背面
*
* @param canvas
* @param bitmap
*/
private void drawCurrentBackArea(Canvas canvas, Bitmap bitmap) {
int i = (int) (mBezierStart1.x + mBezierControl1.x) / 2;
float f1 = Math.abs(i - mBezierControl1.x);
int i1 = (int) (mBezierStart2.y + mBezierControl2.y) / 2;
float f2 = Math.abs(i1 - mBezierControl2.y);
float f3 = Math.min(f1, f2);
mPath1.reset();
mPath1.moveTo(mBeziervertex2.x, mBeziervertex2.y);
mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
mPath1.lineTo(mBezierEnd1.x, mBezierEnd1.y);
mPath1.lineTo(mTouchX, mTouchY);
mPath1.lineTo(mBezierEnd2.x, mBezierEnd2.y);
mPath1.close();
GradientDrawable mFolderShadowDrawable;
int left;
int right;
if (mIsRTandLB) {
left = (int) (mBezierStart1.x - 1);
right = (int) (mBezierStart1.x + f3 + 1);
mFolderShadowDrawable = mFolderShadowDrawableLR;
} else {
left = (int) (mBezierStart1.x - f3 - 1);
right = (int) (mBezierStart1.x + 1);
mFolderShadowDrawable = mFolderShadowDrawableRL;
}
canvas.save();
try {
canvas.clipPath(mPath0);
canvas.clipPath(mPath1, Region.Op.INTERSECT);
} catch (Exception e) {
}
mPaint.setColorFilter(mColorMatrixFilter);
//对Bitmap进行取色
int color = bitmap.getPixel(1, 1);
//获取对应的三色
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);
//转换成含有透明度的颜色
int tempColor = Color.argb(200, red, green, blue);
float dis = (float) Math.hypot(mCornerX - mBezierControl1.x,
mBezierControl2.y - mCornerY);
float f8 = (mCornerX - mBezierControl1.x) / dis;
float f9 = (mBezierControl2.y - mCornerY) / dis;
mMatrixArray[0] = 1 - 2 * f9 * f9;
mMatrixArray[1] = 2 * f8 * f9;
mMatrixArray[3] = mMatrixArray[1];
mMatrixArray[4] = 1 - 2 * f8 * f8;
mMatrix.reset();
mMatrix.setValues(mMatrixArray);
mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y);
mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
canvas.drawBitmap(bitmap, mMatrix, mPaint);
//背景叠加
canvas.drawColor(tempColor);
mPaint.setColorFilter(null);
canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
mFolderShadowDrawable.setBounds(left, (int) mBezierStart1.y, right,
(int) (mBezierStart1.y + mMaxLength));
mFolderShadowDrawable.draw(canvas);
canvas.restore();
}
示例13: drawBar
import android.graphics.drawable.GradientDrawable; //导入方法依赖的package包/类
/**
* Draws a bar.
*
* @param canvas the canvas
* @param xMin the X axis minimum
* @param yMin the Y axis minimum
* @param xMax the X axis maximum
* @param yMax the Y axis maximum
* @param scale the scale index
* @param seriesIndex the current series index
* @param paint the paint
*/
private void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, int scale,
int seriesIndex, Paint paint) {
// Fix negative bars issue in Android 4.2
float temp;
if (xMin > xMax) {
temp = xMin;
xMin = xMax;
xMax = temp;
}
if (yMin > yMax) {
temp = yMin;
yMin = yMax;
yMax = temp;
}
SimpleSeriesRenderer renderer = mRenderer.getSeriesRendererAt(seriesIndex);
if (renderer.isGradientEnabled()) {
float minY = (float) toScreenPoint(new double[] { 0, renderer.getGradientStopValue() }, scale)[1];
float maxY = (float) toScreenPoint(new double[] { 0, renderer.getGradientStartValue() },
scale)[1];
float gradientMinY = Math.max(minY, Math.min(yMin, yMax));
float gradientMaxY = Math.min(maxY, Math.max(yMin, yMax));
int gradientMinColor = renderer.getGradientStopColor();
int gradientMaxColor = renderer.getGradientStartColor();
int gradientStartColor = gradientMaxColor;
int gradientStopColor = gradientMinColor;
if (yMin < minY) {
paint.setColor(gradientMinColor);
canvas.drawRect(Math.round(xMin), Math.round(yMin), Math.round(xMax),
Math.round(gradientMinY), paint);
} else {
gradientStopColor = getGradientPartialColor(gradientMinColor, gradientMaxColor,
(maxY - gradientMinY) / (maxY - minY));
}
if (yMax > maxY) {
paint.setColor(gradientMaxColor);
canvas.drawRect(Math.round(xMin), Math.round(gradientMaxY), Math.round(xMax),
Math.round(yMax), paint);
} else {
gradientStartColor = getGradientPartialColor(gradientMaxColor, gradientMinColor,
(gradientMaxY - minY) / (maxY - minY));
}
GradientDrawable gradient = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
gradientStartColor, gradientStopColor });
gradient.setBounds(Math.round(xMin), Math.round(gradientMinY), Math.round(xMax),
Math.round(gradientMaxY));
gradient.draw(canvas);
} else {
if (Math.abs(yMin - yMax) < 1) {
if (yMin < yMax) {
yMax = yMin + 1;
} else {
yMax = yMin - 1;
}
}
canvas
.drawRect(Math.round(xMin), Math.round(yMin), Math.round(xMax), Math.round(yMax), paint);
}
}