Android的TextView设置padding无效

时间:2022-07-05 18:16:51

I finally found the problem I have to set the background first before setting the padding. Setting the padding then setting the background doesn't work

// does not work
tv.setPadding(20, 20, 20, 20);
tv.setBackgroundResource(R.drawable.border);


// works
tv.setBackgroundResource(R.drawable.border);
tv.setPadding(20, 20, 20, 20);

 

原文地址:https://*.com/questions/18327498/setting-padding-for-textview-not-working