是的,您可以使用 Layoutmanager 来执行此操作,请查看...
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
LinearLayout layoutmanager = new LinearLayout(this);
layoutmanager.setOrientation(LinearLayout.HORIZONTAL);
setContentView(layoutmanager);
LayoutInflater inf = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layleft = (RelativeLayout)inf.inflate(R.layout.firstxml,null);
RelativeLayout layright = (RelativeLayout)inf.inflate(R.layout.secondxml,null);
RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutmanager.addView(layright, 250, 450);
layoutmanager.addView(layleft, relParam);
您可以使用 LinearLayout Vertical 而不是 Horizontal 并确保您使用的两个 xml 都必须只有相对布局..我希望它能解决您的问题