我不知道如何在RelativeLayout的右侧设置TextView。向TextView添加重力是行不通的。感谢您的帮助。Android - 以编程方式在布局中定位TextView
RelativeLayout relativeLayout = new RelativeLayout(context);
relativeLayout.setGravity(Gravity.CENTER_HORIZONTAL); // center in linearLayout_power_stations_bar
textView = new TextView(context);
textView.setText(String.valueOf(nuke_count));
textView.setTextColor(activity.getResources().getColor(R.color.game_powerStationsBar_textOverIcon));
textView.setTextSize(16);
relativeLayout.addView(textView); // TextView over image
relativeLayout.addView(imageView); // adding image
linearLayout_power_stations_bar.addView(relativeLayout); // adding to other layout
有没有你正在做此布局在Java中,而不是在XML理由吗? –