当前位置: 代码迷 >> Android >> 请教listview怎么设置字体大小
  详细解决方案

请教listview怎么设置字体大小

热度:90   发布时间:2016-05-01 22:06:58.0
请问listview如何设置字体大小?
listView = new ListView(this);
1.在不涉及xml布局的情况下,怎么设置字体大小呀?
2.以及如果一行中有两条数据怎么设置其中间隔?

------解决方案--------------------
ListView list = (ListView) findViewById(R.id.list);
adapter = new MyAdapter(this,R.layout.main,
R.id.row_text,
new String[]{"Uno", "Dos", "Tres"} );
list.setAdapter(adapter);
//Custom Adapter class
private class MyAdapter extends ArrayAdapter<String>{
String[] mStrings;
LayoutInflater mInflater;
 
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
mStrings = strings;
mInflater = (LayoutInflater) FirstAct.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = mInflater.inflate(R.layout.main,null, false);
TextView text = (TextView) view.findViewById(R.id.row_text);
text.setText(mStrings[position]);
Spannable str = (Spannable) text.getText();
str.setSpan(new StyleSpan(Typeface.BOLD), 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  
return view;
}
 }
------解决方案--------------------
应该不行的,必须定义自己的布局,也不难,自己写个加载自己的就是了。
  相关解决方案