2013-10-17 23 views
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仍然有底色的效果...

回答

0
circlePaint.setColor(Color.parseColor("#00FFFFFF")); 

其中第2位是阿尔法。 00至FF

+0

呃,非常感谢!我forogot这个..... – log1000