Skip to content Skip to sidebar Skip to footer

How Do Solve Shape Round Rect Too Large To Be Rendered Into A Texture In Android Textbox

I create A shape for Text View Background

One simple workaround should be to revert to software rendering for that view:

Viewview= findViewById(R.id.textView1);
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

...but we've run into a similar problem here and we got the same result you did, the view (and its children) didn't render.

You can also set the layer type of a view from XML:

<TextViewandroid:layerType="software" />

Setting the layerType to "none" instead of software seems to cause the view to draw, but it drew without the rounded corners in a quick test we just tried.

Another approach might be to use a different method of rendering the rounded rectangle, e.g.

  • clipping and drawing the path yourself in onDraw
  • using a PaintDrawable (which supports rounded corners, but must be set from code)
  • breaking the rectangle into three slices -- a top (with rounded corners), middle (just a solid color), and bottom (with rounded corners)

Solution 2:

My Solution is to draw onto the canvas. See below.

If you need to do gradents etc then look at Shader's, https://developer.android.com/reference/android/graphics/LinearGradient.html Should do what you need it too.

/**
 * Created by chris on 04/11/2013
 */publicclassWidgetLinearLayoutextendsLinearLayout {

//Dither and smooth :)privatefinalPaintmPaint=newPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
privatefinalRectFmBound=newRectF();
privatefinalfloat radius;

publicWidgetLinearLayout(Context context) {
    this(context, null);
}

publicWidgetLinearLayout(Context context, AttributeSet attrs, int defStyle) {
    this(context, attrs);
}

publicWidgetLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setBackgroundDrawable(null);
    mPaint.setColor(getResources().getColor(R.color.white));
    mPaint.setStyle(Paint.Style.FILL);
    radius = getResources().getDimension(R.dimen.widget_corner_radius);
    setWillNotDraw(false);
}

@OverrideprotectedvoidonLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    mBound.set(l, t, r, b);
}

@OverrideprotectedvoidonDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawRoundRect(mBound, radius, radius, mPaint);
}
}

Solution 3:

Post a Comment for "How Do Solve Shape Round Rect Too Large To Be Rendered Into A Texture In Android Textbox"