我已经使用 Android Studio 创建了新应用程序并更改了 onCreate 方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.activity_main, new PlaceholderFragment())
.commit();
}
int width = 400;
int height = 20;
RelativeLayout.LayoutParams params;
params = new RelativeLayout.LayoutParams(
width,
height
);
params.leftMargin = 20;
params.topMargin = 200;
TextView textView = new TextView(this);
textView.setText("Text Added dinamically");
textView.setLayoutParams(params);
FrameLayout activityMain = (FrameLayout) findViewById(R.id.activity_main);
activityMain.addView(textView);
}
我希望在距离顶部 200 处看到“动态添加的文本”。事实上,它似乎是顶部的快照。我怎样才能解决这个问题?