當你的線性漸層所需要的顏色不只3種時:
用ShapeDrawable或PaintDrawable

PaintDrawable繼承ShapeDrawable擴展了以下兩個方法來支援圓角

setCornerRadius(float radius)
setCornerRadii(float[] radii)

setCornerRadii每一個角可分別指定 [X_radius, Y_radius]順序為左上、右上、右下、左下
radii = {TLX, TLY, TRX, TRY, BRX, BRY, BLX, BLY}

使用範例:
ShapeDrawable.ShaderFactory tShaderFactory = new ShapeDrawable.ShaderFactory()
{
  @Override
  public Shader resize(int width, int height)
  {
    LinearGradient tLinearGradient = new LinearGradient(0, 0, 0, height,
      new int[]{Color.BLACK, Color.BLACK, Color.YELLOW, Color.WHITE},
      new float[]{0, .35f, .65f, 1}, Shader.TileMode.CLAMP);
    return tLinearGradient;
  }
};

一 ShapeDrawable

ShapeDrawable tShapeDrawable = new ShapeDrawable();
tShapeDrawable.setShape(new RectShape());
tShapeDrawable.setShaderFactory(tShaderFactory);


二 PaintDrawable

PaintDrawable tPaintDrawable = new PaintDrawable();
tPaintDrawable.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
tPaintDrawable.setShaderFactory(tShaderFactory);
 

arrow
arrow
    文章標籤
    Android
    全站熱搜
    創作者介紹
    創作者 你是誰 的頭像
    你是誰

    你是誰的部落格

    你是誰 發表在 痞客邦 留言(0) 人氣()