我正在以编程方式使用TextViews,我需要动态添加新视图并在RelativeLayout父级中设置它们的左/顶位置.
我正在做的是这样的:
RelativeLayout global=(RelativeLayout)findViewById(R.id.global);
TextView view=(TextView)findViewById(R.id.root);
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final TextView childView=new TextView(view.getContext());
lp.addRule(RelativeLayout.ABOVE, view.getId());
childView.setLayoutParams(lp);
childView.setId(childView.getId()+1);
childView.setText(“TRY STRING”);
childView.setTextSize(view.getTextSize());
childView.setWidth(view.getWidth());
childView.setLeft(view.getLeft()+interval);
global.addView(childView);
基本上,我在某个位置(称为视图)有一个textview,我正在尝试在现有的位置和相同的左侧位置上创建一个新的textview.
虽然getLeft()方法正确返回视图的左侧位置,但是当将我将其添加到RelativeL