我試圖使用SquareTextView
來設置地圖標記的集羣圖標的自定義字體,什麼是android-maps-utils-amap
庫擴展TextView的類。在DefaultClusterRenderer
我使用此代碼來設置自定義字體,但沒有效果。所以,請幫助我明白我需要做什麼來改變SquareTextView如何設置SquareTextView TypeFace
private SquareTextView makeSquareTextView(Context context) {
SquareTextView squareTextView = new SquareTextView(context);
Typeface typeface = Typeface.createFromAsset(context.getAssets(), "whatever.ttf");
squareTextView.setTypeface(typeface);
}
的字體,這是SquareTextView
源代碼:
package com.amap.api.maps2d.ui;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;
public class SquareTextView extends TextView {
private int mOffsetTop = 0;
private int mOffsetLeft = 0;
public SquareTextView(Context context) {
super(context);
}
public SquareTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int dimension = Math.max(width, height);
if (width > height) {
mOffsetTop = width - height;
mOffsetLeft = 0;
} else {
mOffsetTop = 0;
mOffsetLeft = height - width;
}
setMeasuredDimension(dimension, dimension);
}
@Override
public void draw(Canvas canvas) {
canvas.translate(mOffsetLeft/2, mOffsetTop/2);
super.draw(canvas);
}
}
你確定你的資產目錄'的Roboto-Italic.ttf'文件,而不是在任何子目錄?另外,如果你想設置應用程序寬字體 – Sourabh