1
有我的佈局文件的片段:與backgound #e9e9e9
如何在android中設置可繪製的塗料顏色與背景?
<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>
有我的自定義繪製和CustomView類片段 layout_1
。頂部的一部分覆蓋底部。
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值? 我已經嘗試設置顏色與阿爾法值1至0xe2f5ff,但我認爲佈局backgound仍然有底色的效果...
呃,非常感謝!我forogot這個..... – log1000