如何通过一个活动显示20个静态xml布局



我有20个xml布局,必须按顺序显示。它们是静态的,不包含任何更新或操作。我只想在每个布局中有一个下一个按钮,并在单击下一个时逐个显示它们。我的问题是,我能用一项活动来完成吗?还是我必须做20个corrs活动来陪伴它??

附言:如果能帮助把布局放在某个循环或其他东西中,我可以给它们命名任何东西。提前感谢任何帮助。

我认为您可以使用ViewFlipper。

ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper);
//Inflate the Views
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater.inflate(R.layout.t1, null);
View v2 = inflater.inflate(R.layout.t2, null);
View v3 = inflater.inflate(R.layout.t3, null);
//Add the views to the flipper
viewFlipper.addView(v1);
viewFlipper.addView(v2);
viewFlipper.addView(v3);
//Move between them
flipper.showNext();
flipper.showPrevious();
不,您不需要新的活动。只需调用setContentView(R.layout.thenextlayout),但有更好的方法可以做到这一点,并根据您的需求进行设计。

我建议将片段与replace()一起使用。如果您不熟悉片段,请考虑使用ViewFlipper。

最新更新