android - 应在此处传递已解析的像素尺寸而不是资源 ID :getResource(). getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT)

标签 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);

我想将 MarginLayoutParams 添加到我的 View 中。但是,它显示错误

should pass resolved pixel dimension instead of resource id here:getResource().getDimession*(ViewGroup.LayoutParams.WRAP_CONTENT)

我该如何解决这个问题?

最佳答案

MATCH_PARENTWRAP_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/

相关文章:

android - 当软键盘弹出时,RecyclerView 不会让项目在底部滚动

java - firebaserecycleradapter 中的 firebaserecycleradapter() 不能应用于

android - 在另一个pendingintent中取消一个AlarmManager的pendingIntent

android - 在 actionbar customview imagebutton 中刷新动画

java - while 循环内的延迟不起作用

android - 无法登录手动安装的 APK 的 Google Play 服务

android - 如何安全地关闭 onstop() 中的 DialogFragment?

java - 如何确保一个函数能够完整地检查一个函数?

使用同一测试帐户在多台设备上进行 Android 应用内结算 v3 测试

android - 将多个 firebase 目录中的所有帖子显示到 recyclerView 中