Exemplo n.º 1
0
 // 为view添加阴影
 public void setShadowForView(View v) {
   Drawable d = v.getBackground();
   int w = v.getLayoutParams().width;
   int h = v.getLayoutParams().height;
   Bitmap bt = Bitmap.createBitmap(w, h, Config.ARGB_8888);
   Canvas mCanvas = new Canvas(bt);
   d.setBounds(0, 0, w, h);
   d.draw(mCanvas);
   Paint paint = new Paint();
   paint.setStrokeWidth(2);
   paint.setARGB(64, 255, 255, 255);
   mCanvas.drawLine(0, 0, w, 0, paint);
   paint.setARGB(39, 76, 76, 76);
   mCanvas.drawLine(0, h, w, h, paint);
   BitmapDrawable bd = new BitmapDrawable(v.getContext().getResources(), bt);
   Compatibility.setBackground(v, bd);
 }
Exemplo n.º 2
0
  /**
   * 为view设置一个折叠的角
   *
   * @param v
   */
  public void setViewTucked(Context context, View v) {
    Drawable d = v.getBackground();
    int w = v.getLayoutParams().width;
    int h = v.getLayoutParams().height;
    int tuck = (int) ImageHlp.changeToSystemUnitFromDP(context, 15);
    Bitmap bt = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Path path = new Path();
    path.moveTo(0, 0);
    path.lineTo(w - tuck, 0);
    path.lineTo(w, tuck);
    path.lineTo(w, h);
    path.lineTo(0, h);
    path.lineTo(0, 0);
    Canvas mCanvas = new Canvas(bt);
    mCanvas.clipPath(path);
    d.setBounds(0, 0, w, h);
    d.draw(mCanvas);

    Path wPath = new Path();
    wPath.moveTo(w - tuck, 0);
    wPath.lineTo(w - tuck, tuck);
    wPath.lineTo(w, tuck);
    wPath.lineTo(w - tuck, 0);
    mCanvas.clipPath(wPath);
    mCanvas.drawARGB(64, 255, 255, 255);

    Canvas mCanvas1 = new Canvas(bt);
    Path bPath = new Path();
    bPath.moveTo(w - tuck, tuck);
    bPath.lineTo(w, tuck);
    bPath.lineTo(w, tuck * 2);
    bPath.lineTo(w - tuck, tuck);
    mCanvas1.clipPath(bPath);
    mCanvas1.drawARGB(39, 0, 0, 0);

    BitmapDrawable bd = new BitmapDrawable(v.getContext().getResources(), bt);
    Compatibility.setBackground(v, bd);
  }