[컴][안드로이드] Gradient 사용 예제

GradientDrawable
	canvas.save();
canvas.translate(contentLeft, 0);

/**
GradientDrawable.Orientation BL_TR draw the gradient from the bottom-left to the top-right
BOTTOM_TOP draw the gradient from the bottom to the top
BR_TL draw the gradient from the bottom-right to the top-left
LEFT_RIGHT draw the gradient from the left to the right
RIGHT_LEFT draw the gradient from the right to the left
TL_BR draw the gradient from the top-left to the bottom-right
TOP_BOTTOM draw the gradient from the top to the bottom
TR_BL draw the gradient from the top-right to the bottom-left
*/
int screenHeight = this.getHeight();
Rect mRect = new Rect(-5, 0, 0, screenHeight);


GradientDrawable mShadowDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[] { 0x00000000, 0xFF000000 });
mShadowDrawable.setShape(GradientDrawable.RECTANGLE);
mShadowDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);

mShadowDrawable.setBounds(mRect);

mShadowDrawable.draw(canvas);
canvas.restore();

 


use gradient xml


	canvas.save();
canvas.translate(contentLeft, 0);

/**
GradientDrawable.Orientation BL_TR draw the gradient from the bottom-left to the top-right
BOTTOM_TOP draw the gradient from the bottom to the top
BR_TL draw the gradient from the bottom-right to the top-left
LEFT_RIGHT draw the gradient from the left to the right
RIGHT_LEFT draw the gradient from the right to the left
TL_BR draw the gradient from the top-left to the bottom-right
TOP_BOTTOM draw the gradient from the top to the bottom
TR_BL draw the gradient from the top-right to the bottom-left
*/
int screenHeight = this.getHeight();
Rect mRect = new Rect(-5, 0, 0, screenHeight);

GradientDrawable mShadowDrawable = (GradientDrawable) getResources().getDrawable(R.drawable.gradient_shadow);
mShadowDrawable.setBounds(mRect); // is it necessary?

mShadowDrawable.draw(canvas);
canvas.restore();

댓글 없음:

댓글 쓰기