如何解决形状圆角矩形太大而无法在android TextBox中渲染为纹理的问题 [英] How Do Solve Shape round rect too large to be rendered into a texture in android TextBox

查看:131
本文介绍了如何解决形状圆角矩形太大而无法在android TextBox中渲染为纹理的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为文本视图背景"创建形状

I create A shape for Text View Background

<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" />

我的textview是:

and my textview is :

 <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" />

当文本较短时,例如

但是当文本太大时,背景和日食logcat都不会显示

but when text is too large not showing background and eclipse logcat show

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

如何解决? 谢谢

推荐答案

我的解决方案是在画布上绘制.见下文.

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

如果您需要进行平地作业等,请查看Shader https://developer.android.com/reference/android/graphics/LinearGradient.html 应该也做您需要的事.

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
 */
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);
}
}

这篇关于如何解决形状圆角矩形太大而无法在android TextBox中渲染为纹理的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆