Set the size of text in ListView
I want to set the tex开发者_StackOverflow中文版t size of the ListView
. I am not use the XML Layout file.
How to do this in coding?
I don't know if there is a way to modify text size of the default ListView
.
I would recommend creating or editing your adapter and overriding the getView
method with something like this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.my_layout, parent,
false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
YourModel model = getItem(position);
holder.text.setText(model.getText());
return convertView;
}
And in your xml you can set the size correctly.
If you didn't watch The world of ListView by Romain Guy, Adam Powell do it.
Once you have found your textview you have access to all it's attributes. So, changing the typeface or style is as simple as the following snippet:
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.text.setTextSize(size)
You can set Layout height and weight as your requirement.
精彩评论