Android - 如何动态更改 fragment 布局

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

我有一个平板电脑应用程序,其中包含一个显示我公司数据的关于 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/

相关文章:

android - 如何在每次切换到 fragment 时不重新加载 Google map

android - 警报在创建后立即运行

android - 始终显示一个按钮

android - 如何设置可绘制资源中位图的大小?

android - 为包含的布局 android 指定文本颜色

FragmentDialog 中的 Android Google map 被 Dialog 自己的灰色覆盖层覆盖

android - 需要从数据库中检索数据

android - Phonegap Android 应用程序在 1.5 中意外关闭

java - Facebook open graph get 'me' 有效,但 'me?fields=name' 返回 oAuth 错误

android - 如何使用 PreferenceFragment?