引用:
LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT ); para.setMargins(20, 20, 20, 20); //left,top,right, bottom para.gravity = Gravity.RIGHT; tv.setLayoutParams(para); tv.setBackgroundResource(R.drawable.icon);