有我的布局文件的片段:
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>
有我的自定义 drawable 和 CustomView 类片段。顶部的部分覆盖底部的。
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();
}
}
但是布局背景对底部有影响,底部对顶部也有影响。
如何确保它们以正确的 RGB 颜色显示,我应该如何处理 RGBA 的 alpha 值?我尝试将颜色设置为 0xe2f5ff,alpha 值为 1,但我认为布局背景仍然对底部颜色有影响......