【声明:】本文是作者(蘑菇v5)原创,版权归作者 蘑菇v5所有,侵权必究。本文首发在简书。如若转发,请注明作者和来源地址!未经授权,严禁私自转载!
代码如下:
LayoutInflater inflater = LayoutInflater.from(CameraActivity.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
TextView textView = (TextView) inflater.inflate(R.layout.text_view, null);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(size);
textView.setText(name);
layoutParams.setMargins(left, 0, 0, 0);
textView.setLayoutParams(layoutParams);
mNameLayout.addView(textView);
效果如下图:

网友评论