Warning: this may be a pre-Lollipop answer.

Fragment doesn't get re-inflated on configuration change, but you can achieve the effect as follows by creating it with a FrameLayout and (re)populating that manually:

public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
FrameLayout frameLayout = new FrameLayout(getActivity());
populateViewForOrientation(inflater, frameLayout);
return frameLayout;
} @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LayoutInflater inflater = LayoutInflater.from(getActivity());
populateViewForOrientation(inflater, (ViewGroup) getView());
} private void populateViewForOrientation(LayoutInflater inflater, ViewGroup viewGroup) {
viewGroup.removeAllViewsInLayout();
View subview = inflater.inflate(R.layout.my_fragment, viewGroup); // Find your buttons in subview, set up onclicks, set up callbacks to your parent fragment or activity here.
}
}

I'm not particularly happy with the getActivity() and related calls here, but I don't think there's another way to get hold of those things.

Change Fragment layout on orientation change的更多相关文章

  1. change legend layout from 'vertical' to 'horizontal' in Paraview

    ********** # get color legend/bar for 'vLUT' in view 'renderView1'vLUTColorBar = GetScalarBar(vLUT, ...

  2. Change Field Layout and Visibility in a List View 在列表视图中更改字段布局和可见性

    This lesson will guide you through the steps needed to select columns displayed in the List View. Fo ...

  3. Android Screen Orientation Change (Screen Rotation) Example

    原文见: http://techblogon.com/android-screen-orientation-change-rotation-example/#

  4. 关于android屏幕适配的问题(drawable-xxxxxxxx,dp,sp,px等等),偶尔看到了android源代码,关于dpi的区分的值

    上一篇博客说了一下.9.png图片http://blog.csdn.net/qq_23195583/article/details/46737419 当然,点九的是指的能够进行拉伸的.那么假设图片不能 ...

  5. Android Configuration change引发的问题及解决方法(转)

    之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...

  6. Android Configuration change引发的问题及解决方法

    之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...

  7. 代码的坏味道(10)——发散式变化(Divergent Change)

    坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...

  8. Training - Problem and Change Management

    Problem Management Problem management seeks to identify the underlying causes of incidents in an IT ...

  9. Oracle 10g Block Change Tracking特性

    Using Block Change Tracking to Improve Incremental Backup Performance 使用块改变跟踪改善增量备份的性能 The block cha ...

随机推荐

  1. Centos + nginx + JBOSS AS 7 搭建Java web application

    最近做了一个Java的web app,一直想在Centos环境中搭建一个完整的web服务器,现在开始动手. 先说说环境: 操作系统: Centos 6.3 WEB服务器: nginx-1.2.5 Ap ...

  2. jq实现瀑布流效果

    <!doctype html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. 写个自动安装JDK的shell脚本

    #!/bin/bash ################################################# # # INSTALL JDK AUTOMATICALLY # # auth ...

  4. WINDOWS+L组合键锁定XP

    在Windows XP时工作时,我们经常要锁定计算机,当计算机被锁定后,只有重新登录才能够使用计算机,从而保证了计算机的安全. WINDOWS+L组合键锁定XP,就是键盘上右边的小窗口+L键 ,可以快 ...

  5. 两种QMultiMap的遍历方法(最好使用只读遍历器)

    留个爪,备查 QMultiMap<QString, QString>& remote_map = my_obj->m_MapVersion; // ccc 这里体现了引用的好 ...

  6. Oracle导出存储过程

    SQL> SELECT * FROM dba_directories ; OWN DIRECTORY_NAME DIRECTORY_PATH ------- ------------------ ...

  7. 计算机视觉code与软件

    Research Code A rational methodology for lossy compression - REWIC is a software-based implementatio ...

  8. iOS设备保持横排方向

    //保持横排方向 -(NSUInteger)supportedInterfaceOrientations{     returnUIInterfaceOrientationMaskLandscapeL ...

  9. .Net remoting 的文件传输

    http://www.codeproject.com/Articles/14100/Dot-Net-Remoting-Handling-Remote-Events-using-Dele

  10. zoj 2100 Seeding

    Seeding Time Limit: 2 Seconds      Memory Limit: 65536 KB It is spring time and farmers have to plan ...