我的Android Studio版本1.2.1.1有问题。正如标题中所提到的,我对API 21/22的预览并没有保持正确的视图大小,但是在手机上,视图看起来就像应该看起来一样。有办法解决这个问题吗?
链接:https://screencloud.net/v/nrjv
我有扩展类TextView,因此它支持自定义字体:
public class FontTextView extends TextView{
public FontTextView(Context context){
super(context);
}
public FontTextView(Context context, AttributeSet attrs){
super(context, attrs);
readAttributes(context, attrs);
}
public FontTextView(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
readAttributes(context, attrs);
}
private void readAttributes(Context context, AttributeSet attrs){
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.FontTextView);
int fontIndex = attributes.getInt(R.styleable.FontTextView_customFont, 0);
this.setTypeface(TypefaceCreator.getTypeface(fontIndex));
attributes.recycle();
}
}
我有一个在应用程序启动时构建这些字体的类:
public class TypefaceCreator {
public static final int HELVETICA_MEDIUM = 0;
public static final int HELVETICA_LIGHT = 1;
public static final int HELVETICA_ITALIC = 2;
public static final int HELVETICA_ROMAN = 3;
private static Typeface light;
private static Typeface italic;
private static Typeface roman;
private static Typeface medium;
private static TypefaceCreator creator;
private TypefaceCreator(Context context){
light = Typeface.createFromAsset(context.getAssets(),"HelveticaNeueLTPro-Lt.otf");
italic = Typeface.createFromAsset(context.getAssets(),"HelveticaNeueLTPro-It.otf");
roman = Typeface.createFromAsset(context.getAssets(),"HelveticaNeueLTPro-Roman.otf");
medium = Typeface.createFromAsset(context.getAssets(),"HelveticaNeueLTPro-Md.otf");
}
public static TypefaceCreator getInstance(Context context){
if(creator == null)
creator = new TypefaceCreator(context);
return creator;
}
public static Typeface getTypeface(int index){
switch(index) {
case HELVETICA_LIGHT:
return light;
case HELVETICA_ITALIC:
return italic;
case HELVETICA_ROMAN:
return roman;
default:
return medium;
}
}
}