Android - 如何动态更改片段布局

Jac*_*yto 7 android android-layout android-screen android-fragments

我有一个平板电脑应用程序,其中包含显示我公司数据的片段.当我在页面上时,我想用屏幕方向动态地改变我的布局,但我还没找到.

如果有人得到了解决方案,请提前感谢

Jac*_*yto 11

@Yume177,我发现了怎么做:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.about);
    rl.removeAllViews();
    rl.addView(View.inflate(myView.getContext(), R.layout.about, null));
}
Run Code Online (Sandbox Code Playgroud)

我有2 RelativeLayout的两个名为"about.xml",用一个布局在DIR RES /布局sw720dp/about.xml我绘制的肖像模式和RES /布局sw720dp土地/ about.xml我的景观绘制.当我旋转平板电脑时,我的布局非常合适.希望我会帮助你