如何在列表视图中获取字体大小并以编程方式为特定项目设置更大

How to get font size in list view and set bigger for a specific item programmatically

列表视图中文本视图的大小为 19SP。我想将第一个位置项目的字体大小设置得更大,例如21SP。我怎样才能以编程方式做到这一点?

提前致谢!

您需要调整适配器中的 getView 方法以满足您的需要。

定义的方法 getView here 为您提供项目在您尝试显示的数据集中的位置。

您需要做的就是根据您要求的位置自定义充气视图

   getView(int position, 
                View convertView, 
                ViewGroup parent){
    //inflate the view
   View v =  LayoutInflator.from(parent).inflate(R.layout.your_layout,parent,false);   
   TextView txt = (TextView) v.findViewById(R.id.your_txt);
   if(position == 0){
   txt.setTextSize(//get the dimen from resources);
   }
   return v;    
  }