应该在这里传递已解析的像素维度而不是资源ID:getResource().getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT)

mas*_*age 6 android

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);
Run Code Online (Sandbox Code Playgroud)

我想添加MarginLayoutParams到我的视图中.但是,它显示错误

应该在这里传递解析的像素维度而不是资源ID:getResource().getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT)

我怎么解决这个问题?

Eug*_*nec 11

MATCH_PARENT并且WRAP_CONTENT确实是LayoutParams宽度和高度的有效输入.

这是过度活跃的皮特.您可以放心地忽略该警告.

选择带下划线的语句,按Alt + Enter,选择问题,选择Ignore for statement/for method.

  • 在AOSP中跟踪为https://code.google.com/p/android/issues/detail?id=226452 (3认同)