我有一个ListView
有一百个滚动良好的项目。我在其中一个中添加了一种自定义字体TextView
,现在它不连贯。我已经尝试过 otf 和 ttf 字体。
这是我的代码(简化):
public class ItemAdapter extends ArrayAdapter<ItemObject> implements
SectionIndexer {
private Typeface myTypeface; // class variable
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_row_layout, parent,
false);
holder = new ViewHolder();
holder.t1 = (TextView) convertView.findViewById(R.id.itemName);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ItemObject io = getItem(position);
String name = io.name;
myTypeface = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/listitemfont.ttf");
holder.t1.setText(name);
holder.t1.setTypeface(myTypeface);
return convertView;
}
有没有更好的办法?