android-动态添加包含WebView的Fragment显示空白
2015-07-11 01:39
531 查看
点击按钮新增包含WebView的Fragment时,WebView显示空白,其中Fragment除了WebView外还有其他控件,当使用activity打开该Fragment,LogCat输出发现已经执行了:
但是WebView是空白的,点击Fragment的其中一个按钮后WebView的内容就显示了,此时觉得是该Fragment没有"获得焦点",修改新增Fragment方法:
修改为:android.R.id.content就可以显示WebView内容。android.R.id.content是根视图,使得该Fragment获得“焦点”。
后来网上查了一下别人不是用LinearLayout,修改为:
<FrameLayout
android:id="@+id/my_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>当新增一个有WebView的Fragment时,WebView显示出内容。
解决办法暂时有两种:
1、如下,使用android.R.id.content,代替你的布局,我的是LinearLayout,但是使用android.R.id.content,Fragment会覆盖原布局的内容,此内容不会清除。getFragmentManager().beginTransaction().add(android.R.id.content,one,"qe").commit();
2、如下,使用FrameLayout代替LinearLayout,此时不会像android.R.id.content覆盖掉原布局的东西,而是根据FrameLayout所在layout进行布局
<FrameLayout
android:id="@+id/my_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
暂时只是记录解决的方法,从以上两种解决方案看出,布局对于嵌入到Fragment的WebView的内容显示是有影响的,改天再查明是什么原因。
@Override public void onPageFinished(WebView view, String url)
但是WebView是空白的,点击Fragment的其中一个按钮后WebView的内容就显示了,此时觉得是该Fragment没有"获得焦点",修改新增Fragment方法:
getFragmentManager().beginTransaction().add(android.R.id.content,one,"qe").commit();原来我使用的不是android.R.id.content这个值,而是设置到自己定义的一个:
<LinearLayout android:id="@+id/my_content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:focusable="true" />
修改为:android.R.id.content就可以显示WebView内容。android.R.id.content是根视图,使得该Fragment获得“焦点”。
后来网上查了一下别人不是用LinearLayout,修改为:
<FrameLayout
android:id="@+id/my_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>当新增一个有WebView的Fragment时,WebView显示出内容。
解决办法暂时有两种:
1、如下,使用android.R.id.content,代替你的布局,我的是LinearLayout,但是使用android.R.id.content,Fragment会覆盖原布局的内容,此内容不会清除。getFragmentManager().beginTransaction().add(android.R.id.content,one,"qe").commit();
2、如下,使用FrameLayout代替LinearLayout,此时不会像android.R.id.content覆盖掉原布局的东西,而是根据FrameLayout所在layout进行布局
<FrameLayout
android:id="@+id/my_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
暂时只是记录解决的方法,从以上两种解决方案看出,布局对于嵌入到Fragment的WebView的内容显示是有影响的,改天再查明是什么原因。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories