我正在開發一個跨平臺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的父視圖的背景時。
任何人都知道這裏發生了什麼,或者我應該探索什麼途徑?
由於作爲一個新手,我無法在原帖中發佈,因此這裏有截圖 http://i.imgur.com/ejHvJ.png和http://i.imgur.com的鏈接/l1PNU.png – 2012-04-19 16:00:48