How to allow shape to round a rectangle too big to display in a texture in android TextBox

I create a background form with text

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#800e1520" android:endColor="#801e252f" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /> 

and my text:

  <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/rel1" android:layout_centerHorizontal="true" android:layout_marginTop="8dp" android:background="@drawable/rounded_corners" android:gravity="right" android:lineSpacingExtra="6dp" android:supportsRtl="true" android:text="@string/hello_world" android:textColor="#FFFFFF" /> 

when the text is short like this TextBoxImage

but when the text is too large without showing the background image and viewing the eclipse trap

 Shape round rect too large to be rendered into a texture (424x5884, max=2048x2048) 

how to solve it? thanks

+4
source share
3 answers

My solution is to draw on canvas. See below.

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

 /** * Created by chris on 04/11/2013 */ public class WidgetLinearLayout extends LinearLayout { //Dither and smooth :) private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); private final RectF mBound = new RectF(); private final float radius; public WidgetLinearLayout(Context context) { this(context, null); } public WidgetLinearLayout(Context context, AttributeSet attrs, int defStyle) { this(context, attrs); } public WidgetLinearLayout(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); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mBound.set(l, t, r, b); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRoundRect(mBound, radius, radius, mPaint); } } 
+2
source

Edit: The easiest solution is to get rid of rounded corners. If you remove the rounded corners and use a simple rectangle, the hardware rendering will no longer create one large texture for the background layer and will no longer exceed the texture size limit.


One simple way to solve the problem is to return to software rendering for this view:

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

... but we ran into a similar problem, and we got the same result as you, the view (and its children) did not display.

You can also set the view layer type from XML :

 <TextView android:layerType="software" /> 

Setting the layerType type to "none" instead of software seems to trigger a scan, but it painted without rounded corners in the quick test we just tried.

Another approach could be to use another way to render a rounded rectangle, for example.

  • cropping and drawing paths in onDraw
  • using PaintDrawable (which supports rounded corners, but must be set from code)
  • the rectangle is divided into three sections - the top (with rounded corners), middle (only solid color) and the bottom (with rounded corners).
+4
source

You can also try to make your background . 9.png

0
source

All Articles