TextView textView = new TextView(getActivity());
textView.setBackgroundResource(R.drawable.shape_item_talker_realm);
textView.setText(skill.skill_name);
textView.setTextSize(12);
textView.setPadding(12, 12, 12, 12);
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.userIndexTagText));
ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
lp.setMargins(0, 0, 15, 15);
我想将 MarginLayoutParams
添加到我的 View 中。但是,它显示错误
should pass resolved pixel dimension instead of resource id here:
getResource().getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT)
我该如何解决这个问题?
最佳答案
MATCH_PARENT
和 WRAP_CONTENT
确实是 LayoutParams
宽度和高度的有效输入。
这是多动症 Lint在行动中。您可以安全地忽略该警告。
选择带下划线的语句,按Alt+Enter,选择问题,选择Ignore for statement/for method。
关于android - 应在此处传递已解析的像素尺寸而不是资源 ID :getResource(). getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39596970/