【问题标题】:Android - How to dynamically change fragment layoutAndroid - 如何动态更改片段布局
【发布时间】:2013-07-24 08:45:07
【问题描述】:

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

如果有人得到解决方案,在此先感谢

【问题讨论】:

    标签: android android-layout android-fragments android-screen


    【解决方案1】:

    @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 个名为“about.xml”的 RelativeLayout,其中一个布局在目录 res/layout-sw720dp/about.xml 中,我的可绘制用于纵向模式和 res/layout -sw720dp-land/about.xml 与我的风景画。当我旋转我的平板电脑时,我的布局非常适合。希望能帮到你

    【讨论】:

    • 当我这样做时它给出了空指针异常?没有setcontentciew吗?
    【解决方案2】:

    【讨论】:

    • 链接失效,发布实际答案。
    最近更新 更多