XML 파일의 일부 데이터가 /res/values/mydata.xml에 있습니다. 사용자 정의 글꼴을 사용하여 목록보기에 데이터를 표시하려고합니다. 모든 것이 에뮬레이터에서 훌륭하지만 실제 장치 (Samsung Galaxy 탭 10.1 2 with android 4.0.3 사용)는 스크롤 목록보기가 너무 느립니다. 실제로 기본 글꼴로 잘 작동하지만 사용자 글꼴을 설정할 때 문제가 나타납니다.사용자 정의 글꼴을 설정할 때 느린 목록보기
이 내 자바 코드 :
public class ShowFoodCalorie extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// reading data from xml file
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,
R.id.textView1, getResources().getStringArray(R.array.food_cal)));
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] string) {
super(context, resource, textViewResourceId, string);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.show_all, parent, false);
String[] item = getResources().getStringArray(R.array.food_cal);
TextView tv = (TextView) row.findViewById(R.id.textView1);
try {
Typeface font = Typeface.createFromAsset(getAssets(),"myFont.ttf");
tv.setTypeface(font);
} catch (Exception e) {
Log.d("Alireza", e.getMessage().toString());
}
tv.setText(item[position]);
return row;
}
}
이 문제가 무엇입니까? 내 장치에 관한거야? 어떤 해결책이 나를 도울 수 있습니다.
Typeface font = Typeface.createFromAsset(getAssets(),"myFont.ttf");
당신은, 당신의 어댑터의 생성자에 한 번 그렇게 font
멤버 변수를 확인하고 당신의 TextView
에 setTypeface(font)
를 호출하는 변수를 사용하는 것보다해야 감사
감사합니다. 작동하고있어. 그리고 귀하의 조언을 주셔서 감사합니다 – IndieBoy
우수 답변, 이것을 주셔서 감사합니다. –
아래 링크에는 @WarrenFaith가 제안한 convertView/ViewHolder 패턴에 대한 유용한 정보가 있습니다. [http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/](http://lucasr.org/2012/04/05/performance-tips-for-androids- 목록보기/) – MemoryLeak