2

我用它来通过 textView

textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

但现在我想个性化颜色并将其旋转 45° 以适应内容的对角线。

我绑的东西:

我虽然关于扩展 textview 小部件并覆盖 onDraw 方法..但我在设计方面非常初学者......

那么如何在 textView 上绘制红色(颜色)旋转线有什么帮助吗?

4

3 回答 3

2

增加玛雅尼的回应

@Override
protected void onDraw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(strikeThroughColor);
    paint.setStyle(Paint.Style.FILL);
    paint.setFakeBoldText(true);
    paint.setStrikeThruText(true);
    paint.setStrokeWidth(strikeThroughWidth);
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    super.onDraw(canvas);
    float width = getWidth();
    float height = getHeight();
    canvas.drawLine(width / 10, height / 10, (width - width / 10), (height - height / 10), paint);
}
于 2012-08-07T15:23:25.057 回答
0

For that, follow the below steps:

  1. Create a custom TextView by extending View class
  2. Declare this custom textview inside XML layout same like we do for TextView, Button widgets.

For example:

  class CustomTextView extends View {
        private int mColor;
        private int mRotationAngle, mRotationW, mRotationH;

            private String mText;
         public CustomTextView(Context context) { 
            super(context);
            // set default parameters
            mColor = Color.WHITE;
            mRotationAngle = 0;
         }

         public void SetColor(int newcolor) {
            mColor = newcolor;
            this.invalidate();
         } 

       public void SetRotation(int newangle, int neww, int newh) {
        mRotationAngle = newangle;
        mRotationW = neww;
        mRotationH = newh;
        this.invalidate();
    }

       public void SetText(String newtext) {
            mText = newtext;
            this.invalidate();
        }

    @Override 
        protected void onDraw(Canvas canvas) { 
            Paint paint = new Paint(); 
            paint.setStyle(Paint.Style.FILL); 
            canvas.rotate(mRotationAngle,mRotationW,mRotationH);
            canvas.drawText(mText, 0, 0, paint);
            super.onDraw(canvas); 
        } 
    }

Update:

Check for Specifying “strikethrough” on a section of TextView text

于 2012-08-07T12:46:37.723 回答
0

使用以下方法,您可以实现此功能而不会弄乱 Java 代码中的 UI:

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_centerVertical="true">

                    <TextView
                        android:id="@+id/textview1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentStart="true"
                        android:text="$99"
                        android:textSize="12sp" />

                    <View
                        android:layout_width="0dp"
                        android:layout_height="1dp"
                        android:layout_centerVertical="true"
                        android:layout_alignLeft="@+id/textview1"
                        android:layout_alignRight="@+id/textview1"
                        android:background="@color/fav_dark_red_color" />
                </RelativeLayout>
于 2016-12-20T06:17:04.227 回答