【问题标题】:How to change the font size of a ListView dynamically?如何动态更改 ListView 的字体大小?
【发布时间】:2010-07-12 12:37:01
【问题描述】:

如何动态更改 ListView 的字体大小?

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    使用自定义 ListAdapter,覆盖 getView,在初始化 Adapter 时设置参数(textSize)...

    public class MyListAdapter extends ArrayAdapter<String> {
        private String[] stringArray = null;
        private int textSize,itemLayout;
        public MyListAdapter(Context context, 
                String[] objects,int textSize) {
            super(context, R.layout.la_item, objects);
            stringArray = objects;
            itemLayout = R.layout.la_item;
            this.textSize = textSize;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null)
            {
                LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = vi.inflate(itemLayout, null);
            }
            TextView tv = (TextView)convertView.findViewById(R.id.itemText);
            tv.setTextSize(textSize); // SET THE TEXT SIZE!
            tv.setText(stringArray[position]);
            return convertView;
        }
    
    }
    

    R.layout.la_item 是一个带有 TextView 的简单线性布局......

    请参阅this 了解如何使用 ListAdapter...

    【讨论】:

    • 这会设置文本大小,它不会像 OP 想要的那样动态更改它?
    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多