ViewPager中嵌套Fragment不显示问题
2016-06-13 11:36
411 查看
今天遇到一个奇葩问题,原因也很令人崩溃
原来的布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mymusic.MainActivity" >
<include layout="@layout/main_top" />
<android.support.v4.view.ViewPager
android:id="@+id/main_content_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
这是主布局文件,看着是不是没什么问题,界面也能显示出来
程序运行时发现中间嵌套的Fragment界面没显示出来,是空白的,本来一直认为是控制代码哪里错了,找了半天也没找出来哪里错了。
最后才发现是上面的布局文件的问题。正确的是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.mymusic.MainActivity" >
<include layout="@layout/main_top" />
<android.support.v4.view.ViewPager
android:id="@+id/main_content_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
少写了一句代码:如果不填上下面的这句代码,LinearLayout默认是水平布局的,中间区域的ViewPager当然显示不出来了
原来的布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mymusic.MainActivity" >
<include layout="@layout/main_top" />
<android.support.v4.view.ViewPager
android:id="@+id/main_content_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
这是主布局文件,看着是不是没什么问题,界面也能显示出来
程序运行时发现中间嵌套的Fragment界面没显示出来,是空白的,本来一直认为是控制代码哪里错了,找了半天也没找出来哪里错了。
最后才发现是上面的布局文件的问题。正确的是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.mymusic.MainActivity" >
<include layout="@layout/main_top" />
<android.support.v4.view.ViewPager
android:id="@+id/main_content_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
少写了一句代码:如果不填上下面的这句代码,LinearLayout默认是水平布局的,中间区域的ViewPager当然显示不出来了
android:orientation="vertical"
相关文章推荐
- 六-Statistics统计工具功能详解与应用
- TouchSlide触屏滑动特效插件的使用
- 类斐波那契问题中动态规划的时间复杂度优化
- 关于stress strain的 网站,可以作为一个参考书籍
- [leetcode] 355. Design Twitter
- 厚积薄发,拥抱.NET 2016
- android中src和background区别
- 使用usb术语详解
- java并发编程(七)--使用synchronized获取互斥锁的几点说明
- UIButton的详细使用
- PHP+MySQL存储数据常见中文乱码问题小结
- Swift中的数组和字典
- 线性常系数微分方程
- Python中的Map/Reduce
- js: 字符集
- 银联在线Java接口开发
- windows中Django安装教程
- php关闭错误提示
- Android浏览器多窗口webview界面截屏心得
- JAVA-找不到或无法加载主类