0

テキストを含むカスタム ビューを実装しています。テキストは onDraw で描画されます。

私の問題は、テキストが TextView オブジェクトのテキストのように見えるようにしたいのですが、スタイルと書体の設定に慣れていないことです。

新しく作成した Paint オブジェクトで最終的に描画されたテキストは、TextView とは異なって見えます。それらの TextView オブジェクトと同じようにテキストが描画されることを望みます。

助けてください!

====================
問題を言い換えると:

View を拡張するカスタム ビューで、新しい Paint オブジェクト mPaint を使用して、onDraw メソッドで mPaint.drawText を呼び出します。しかし、描画されたテキストはデフォルトの TextView とは異なって見えます。線は細く、滑らかではありません (昆虫に噛まれたように)。TextView と同じ外観にしたいだけです。

4

2 に答える 2

1
 public class CustomText extends TextView { 
 public CustomText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
    Typeface typeface = Typeface.createFromAsset(context.getAssets(),
    "fonts/your_font.ttf");
    setTypeface(typeface);

}

public CustomText(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    Typeface typeface = Typeface.createFromAsset(context.getAssets(),
    "fonts/fonts/your_font.ttf");
    setTypeface(typeface);

}

public CustomText(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
Typeface typeface = Typeface.createFromAsset(context.getAssets(),
"fonts/fonts/your_font.ttf");
setTypeface(typeface);
    }

}

CustomTextclass/xml で を使用します。

これがあなたを助けることを願っています。

于 2011-04-04T12:50:40.403 に答える
0

You can create a custom view by extending TextView as a parent view. by doing this you will get all the default features that textView has and plus you can add other custom features as per your requirements.

于 2011-04-04T09:55:07.413 に答える