[英]how to set the drawable paint color with background in android?
there is the snippet of my layout file: layout_1
with backgound #e9e9e9
我的布局文件的代码段是:
layout_1
带有背景#e9e9e9
<LinearLayout android:id="@+id/layout_1"
android:layout_width="wrap_content"
android:background="#e9e9e9"
android:layout_height="wrap_content"
>
...
<com.test.android.CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
...
</LinerLayout>
<LinearLayout android:id="@+id/layout_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...
<com.test.android.CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
...
</LinerLayout>
There is my custom drawable and CustomView classes snippets. 有我的自定义drawable和CustomView类片段。 The top one partly cover the bottom one.
顶部部分覆盖底部。
public class NodeDrawable extends Drawable {
//...
protected ShapeDrawable shapeDrawableBottom;
protected ShapeDrawable shapeDrawableTop;
@Override
public void draw(Canvas canvas) {
Paint circlePaint = shapeDrawableBottom.getPaint();
circlePaint.setColor(DEFAULT_COLOR_BOTTOM);//DEFAULT_COLOR_BOTTOM = 0xe2f5ff
circlePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
shapeDrawableBottom.setBounds();
shapeDrawableBottom.draw(canvas);
Paint circlePaint = shapeDrawableTop.getPaint();
circlePaint.setColor(DEFAULT_COLOR_TOP);//DEFAULT_COLOR_TOP = 0x1f8fd2
circlePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
shapeDrawableBottom.setBounds();
shapeDrawableTop.draw(canvas);
}
//...
}
public class CustomView extends View {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
buildDrawables();
}
private void buildDrawables() {
mCustomDrawable = new CustomDrawable();
}
}
But the layout background have an effect on the bottom one and the bottom one effect the top one either. 但是,布局背景会影响底部的背景,而底部的背景则会影响顶部的背景。
How can i ensure them displayed in correct RGB color, what i should do with the RGBA's alpha value? 我如何确保它们以正确的RGB颜色显示,该如何处理RGBA的alpha值? I have tried set the color to 0xe2f5ff with alpha value 1, but i think the layout backgound still have an effect on the bottom color...
我试过将颜色设置为0且ealpha值为1,但是我认为布局背景对底色仍然有影响...
circlePaint.setColor(Color.parseColor("#00FFFFFF"));
where first 2 digit is for Alpha. 前2位数字代表Alpha。 00 to FF
00至FF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.