我有一个平板电脑应用程序,其中包含一个显示我公司数据的关于 fragment 。当我在页面上时,我想根据屏幕方向动态更改我的布局,但我还没有找到方法。
如果有人得到了解决方案,在此先感谢
最佳答案
@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));
}
我有 2 个 RelativeLayout 都命名为“about.xml”,其中一个布局在目录 res/layout-sw720dp/about.xml 中,我的 drawable 用于纵向模式和 res/layout -sw720dp-land/about.xml 我的景观可绘制。当我旋转我的平板电脑时,我的布局非常适合。希望我能帮到你
关于Android - 如何动态更改 fragment 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829154/