【问题标题】:How to get font size in list view and set bigger for a specific item programmatically如何在列表视图中获取字体大小并以编程方式为特定项目设置更大
【发布时间】:2018-01-22 08:39:41
【问题描述】:

列表视图中文本视图的大小为 19SP。我想将第一个位置项的字体大小设置得更大,例如21SP。如何以编程方式进行?

提前致谢!

【问题讨论】:

  • 只需在运行时为所有情况设置大小,因为我不喜欢从 listview 中的 textview 获取字体大小

标签: android listview font-size


【解决方案1】:

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

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

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

   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;    
  }

【讨论】:

  • 我是这样做的,只是想知道如何设置文字大小。经过一番研究,我知道如何编码。还是谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-01
  • 1970-01-01
  • 2012-09-25
  • 1970-01-01
相关资源
最近更新 更多