Change Fragment layout on orientation change
Warning: this may be a pre-Lollipop answer.
A 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的更多相关文章
- change legend layout from 'vertical' to 'horizontal' in Paraview
********** # get color legend/bar for 'vLUT' in view 'renderView1'vLUTColorBar = GetScalarBar(vLUT, ...
- 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 ...
- Android Screen Orientation Change (Screen Rotation) Example
原文见: http://techblogon.com/android-screen-orientation-change-rotation-example/#
- 关于android屏幕适配的问题(drawable-xxxxxxxx,dp,sp,px等等),偶尔看到了android源代码,关于dpi的区分的值
上一篇博客说了一下.9.png图片http://blog.csdn.net/qq_23195583/article/details/46737419 当然,点九的是指的能够进行拉伸的.那么假设图片不能 ...
- Android Configuration change引发的问题及解决方法(转)
之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...
- Android Configuration change引发的问题及解决方法
之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...
- 代码的坏味道(10)——发散式变化(Divergent Change)
坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...
- Training - Problem and Change Management
Problem Management Problem management seeks to identify the underlying causes of incidents in an IT ...
- Oracle 10g Block Change Tracking特性
Using Block Change Tracking to Improve Incremental Backup Performance 使用块改变跟踪改善增量备份的性能 The block cha ...
随机推荐
- VS 调试相关
最近用VS2013 调试遇到的一点小问题,老年痴呆做一下记录. 1. IIS 用 w3wp.exe 调试: IIS 中的文件系统与工程的保持一致,否则断点不会命中: 发布文件系统后,重启站点对应的应用 ...
- window—BAT脚本
bat脚本注释方法: 1.:: 注释内容(第一个冒号后也可以跟任何一个非字母数字的字符) 2.rem 注释内容(不能出现重定向符号和管道符号) 3.echo 注释内容(不能出现重定向符号和管道符号)〉 ...
- 解决类型“System.Web.UI.UpdatePanel”不具有名为“Gridview”的公共属性,
类型“system.web.ui.updatepanel” 不具有名为“XXX”的公共属性,其实原因很简单.就是少了一个<ContentTemplate></ContentTempl ...
- EAFP和LBYL 两种防御性编程风格
EAFP:Easier to ask for forgiveness than permission 获得事后原理总是比事先得到许可要容易的多. 这个EAFP在python中表现的比较多.EAFP,T ...
- poj3709
首先我们发现将一段数变为同一个数比间隔着搞肯定优,因为数列是升序的,然后不难得到方程式f[i]=min(f[j]+sum[i]-sum[j]-(i-j)*a[j+1]) (i-j>=m)简单的斜 ...
- ☀【组件 - 工具】Parallax 视差
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Android 布局之DrawLayout
在刚开始学android的时候肯定会知道,android的主要的布局就是LinearLayout.RelativeLayout.FramLayout.AbsoluteLayout.以及TableLay ...
- Spark(Hive) SQL中UDF的使用(Python)
相对于使用MapReduce或者Spark Application的方式进行数据分析,使用Hive SQL或Spark SQL能为我们省去不少的代码工作量,而Hive SQL或Spark SQL本身内 ...
- CXF Service Interceptor请求,响应报文之控制台输出
一:定义接口 @WebService(targetNamespace = "http://www.unionpay.com/client/appprovider", name = ...
- HDU 3507 Print Article(DP+斜率优化)
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...