에이치의 모바일 앱 개발
View-ImageView-Gradient 본문
기본적으로 안드로이드에서는 start, center, end 총 3군데의 색상을 지정하여 그라데이션 효과를 얻을 수 있습니다.
하지만 PaintDrawable로 색상 작업을 통해 다양한 색을 그라데이션으로 표현 할 수 있습니다.
ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
float x0 = 0;
float y0 = 0;
float x1 = width;
float y1 = height;
int[] colors = new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.WHITE, Color.BLACK};
float[] positions = new float[]{0, 0.2f, 0.4f, 0.6f, 0.8f, 1};
return new LinearGradient(x0, y0, x1, y1, colors, positions, Shader.TileMode.REPEAT);
}
};
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
paintDrawable.setShaderFactory(shaderFactory);
binding.gradientImg.setBackground(paintDrawable);
'Android > Android 개발 소스' 카테고리의 다른 글
View-RecyclerView (0) | 2019.02.20 |
---|---|
View-ImageView-Picasso-blur (0) | 2019.02.20 |
Battery-Awake, Sleep (0) | 2019.02.20 |
View-TextView-link (0) | 2019.02.18 |
롬곡 코드 (0) | 2018.09.21 |
Comments