2012-04-19 81 views
0

我正在开发一个跨平台android/ios框架的android一半,它可以让你在两个平台上都可以编写应用程序。我这样说是因为这意味着我不能使用9贴片之类的东西来获得这种效果。在https://github.com/mschulkind/cordova-true-native-android使用自定义背景drawables时损坏的EditText背景

下面的完整代码是问题的两张截图:

- 图像删节,因为我太新是这个有用的。我将不得不加入他们时,我不再是一个newbie.-

这里的时候提拉被定为的背景,产生从https://github.com/mschulkind/cordova-true-native-android/blob/master/src/org/apache/cordova/plugins/truenative/ViewPlugin.java#L146

// Borrowed from: 
    // http://www.betaful.com/2012/01/programmatic-shapes-in-android/ 
    private class ViewBackground extends ShapeDrawable { 
    private final Paint mFillPaint, mStrokePaint; 
    private final int mBorderWidth; 

    public ViewBackground(
     Shape s, int backgroundColor, int borderColor, int borderWidth) { 
     super(s); 

     mFillPaint = new Paint(this.getPaint()); 
     mFillPaint.setColor(backgroundColor); 

     mStrokePaint = new Paint(mFillPaint); 
     mStrokePaint.setStyle(Paint.Style.STROKE); 
     mStrokePaint.setStrokeWidth(borderWidth); 
     mStrokePaint.setColor(borderColor); 

     mBorderWidth = borderWidth; 
    } 

    @Override 
    protected void onDraw(Shape shape, Canvas canvas, Paint paint) { 
     shape.resize(canvas.getClipBounds().right, canvas.getClipBounds().bottom); 

     Matrix matrix = new Matrix(); 
     matrix.setRectToRect(
      new RectF(
      0, 0, 
      canvas.getClipBounds().right, canvas.getClipBounds().bottom), 
      new RectF(
      mBorderWidth/2, mBorderWidth/2, 
      canvas.getClipBounds().right - mBorderWidth/2, 
      canvas.getClipBounds().bottom - mBorderWidth/2), 
      Matrix.ScaleToFit.FILL); 
     canvas.concat(matrix); 

     shape.draw(canvas, mFillPaint); 
     if (mBorderWidth > 0) { 
     shape.draw(canvas, mStrokePaint); 
     } 
    } 
    } 

这已经发生了两个可绘制代码直接EditText,当我将它设置为EditText的父视图的背景时。

任何人都知道这里发生了什么,或者我应该探索什么途径?

+0

由于作为一个新手,我无法在原帖中发布,因此这里有截图 http://i.imgur.com/ejHvJ.png和http://i.imgur.com的链接/l1PNU.png – 2012-04-19 16:00:48

回答

0

看起来像你想绘制一个圆角的矩形。

要实现这种风格,使用XML可绘制更简单。

您只需将XML文件放入drawable /目录即可。在这里你可以描述所需的形状。 关于XML可绘制的一些文档在这里:http://idunnolol.com/android/drawables.html 看看标签。

+0

我知道XML drawable,但在这种情况下它不是一个选项。所有参数都是直接在javascript中指定的,所以没有机会使用XML;它必须以编程方式。 – 2012-04-19 23:25:13