English 中文(简体)
在使用习俗背景时,对应的EditText背景
原标题:Corrupted EditText backgrounds when using custom background drawables
  • 时间:2012-04-19 15:58:19
  •  标签:
  • java
  • android

I m working on the android half of a cross-platform android/ios framework that lets you write apps in JS that work on both platforms. I say this because it means I can t use things like 9-patches to get this effect. Full code at https://github.com/mschulkind/cordova-true-native-android

这里有两个问题简介:

• 由于我太新,因而重复了时间。 当我不再是一个新事物时,我必须补充。 ——

Here s the code that generates the drawable from 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周围父母观点的背景时。

Anyone have an idea of what s going on here or what avenues I should explore?

问题回答

象你一样,希望汲取一个四舍五入的教训。

为了达到这种风格,更简单的是使用一种可资借鉴的XML。

You simply put a XML file into the drawable/ directory. Here you can describe the desired shape. Some documentation about XML drawables is here : http://idunnolol.com/android/drawables.html Look at the tag.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签