Android: how to get value of “listPreferredItemHeight” attribute in code?

后端 未结 4 1146
借酒劲吻你
借酒劲吻你 2020-12-08 22:03

The below code gives Resources$NotFoundException

TypedValue value = new TypedValue();
((Activity)context).getResources().getValue(android.R.attr         


        
4条回答
  •  春和景丽
    2020-12-08 22:19

    Femi's answer was very helpful. Without wanting to detract from his answer, I've taken the logic and placed it in a library convenience method that you should be able to plug-and-play. I plan on updating the code with other attribute methods over time. I hope it proves useful to someone.

    (Note that I discovered Resources.getDisplayMetrics() seems to be an easier way to return display metrics rather than querying the WindowManager.)

提交回复
热议问题