1.首先是当android2.3.3之前还是用着android-support-v4.jar来加载Fragment时。

a.在xml布局应该如何定义呢?

答案:用FrameLayout标签来定义(在android 3.0之后的版本就是好似用fragment标签)

本人尝试用其他Layout,但是类似不行(不知道是不是人品问题,不过用FrameLayout的话100%可以)

然后就以下面的代码来加载Fragment!

FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();

transaction.replace(R.id.my_frameLayout,new Fragment());

transaction.commit();

2.本人曾经出现一个问题:就是布局在上面的Fragment(就是FrameLayout)死活都要盖住他的下面的Fragment的内容。

当时一时半刻不管怎么改。就是弄不好!

这两天人品爆发。尝试把布局换一下位置。居然好了!

我贴一下xml的代码吧!

之前的代码:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >

<FrameLayout

  android:id="@+id/title_fragment"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <FrameLayout
    android:id="@+id/content_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
    android:id="@+id/bottom_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    </FrameLayout>
  </FrameLayout>

</FrameLayout>

</LinearLayout>

更改后:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >

<FrameLayout

  android:id="@+id/title_fragment"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  </FrameLayout>

<FrameLayout
    android:id="@+id/content_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  </FrameLayout>

<FrameLayout
    android:id="@+id/bottom_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    </FrameLayout>

</LinearLayout>

后来才知道这个FrameLayout(假如加载Fragment的话)里面是尽量不要放子控件的,否则加载Fragment就会把里面的子控件内容挡住。

3.这两天更新了android-SDK-4.4.2,就顺便更新了ADT(ADT不知道是什么的话。我劝你还是别看了)

然后今天打包时突然很多类都打了红叉。打开一看错误是:

This fragment should provide a default constructor (a public constructor with no arguments)

大概意思是说。用这个fargment时。一定要留一个什么参数都不给的的构造方法!

然后我又去看看官方写的demo。基本都是 有

public static Fragment getInstance(boolean isTest) {
  TestFragment instance = new TestFragment();

  instance.isTest = isTest;
  return instance;
}

类似的static 方法。

大概意思就是说:传参只能等对象实例化后才能赋值!

这个不算错误。只是过不了android的打包工具检查而已!

也算android强制要求代码要规范吧!

关于android fragment 某些使用记录的更多相关文章

  1. android fragment 博客 学习记录

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37992017 上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和 ...

  2. Android Fragment 解析和使用

    Android Fragment的生命周期和Activity类似,实际可能会涉及到数据传递,onSaveInstanceState的状态保存,FragmentManager的管理和Transactio ...

  3. Android Fragment 生命周期及其API使用(建议使用自定义View替换Fragment)

    我为什么不主张使用Fragment Fragment:( Fragment就相当于一个有生命周期的View,它的生命周期被所在的Activity的生命周期管理 ) 生命周期回调说明: onAttach ...

  4. Android Fragment详解

    一.什么是Fragment Android在3.0中引入了fragments的概念,主要目的是用在大屏幕设备上--例如平板电脑上,支持更加动态和灵活的UI设计.平板电脑的屏幕要比手机的大得多,有更多的 ...

  5. Android Fragment 生命周期及其正确使用(建议使用自定义View替换Fragment)

    使用Fragment 官方例子中显示: 例如:一个学生Fragment,需要传入studentId,进行http请求显示,那么setArguments后防止杀掉Fragment后,参数为0,显示不了数 ...

  6. Android编程权威指南笔记3:Android Fragment讲解与Android Studio中的依赖关系,如何添加依赖关系

    Android Fragment 当我在学习时,了解了Fragment词汇 Fragment是一种控制器对象,我就把所了解的简单说一下.activity可以派fragment完成一些任务,就是管理用户 ...

  7. Android: Fragment编程指南

    本文来自于www.lanttor.org Fragment代表了Activity里的一个行为,或者Activity UI的一部分.你可以在一个activity里构造多个Fragment,也可以在多个a ...

  8. 【Android自学日记】【转】Android Fragment 真正的完全解析(下)

    上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和各种API,如果你还不了解,请看:Android Fragment 真正的完全解析(上). 本篇将介绍上篇博客提到的:如何管理Frag ...

  9. Android Fragment使用(四) Toolbar使用及Fragment中的Toolbar处理

    Toolbar作为ActionBar使用介绍 本文介绍了在Android中将Toolbar作为ActionBar使用的方法. 并且介绍了在Fragment和嵌套Fragment中使用Toolbar作为 ...

随机推荐

  1. 关于Android中50M+的文本入库处理细节

    好久没有写技术文章,明早4点还要爬起来赶飞机,感觉这个坑有必要记录一下,以慰藉一下自己脆弱的灵魂.周一和周二忙了2天的样子才解决这个问题,中间填了不少的坑,反正已经夜深了,慢慢地记录一点. 场景:项目 ...

  2. Windows Live Writer离线写CSDN博客

    初始化配置 http://blog.csdn.net/csdnproduct/article/details/27504397 代码着色功能插件: http://www.cnblogs.com/cmt ...

  3. ADAMS与外部程序通信(Adams Command Server)

    The Adams Command Server is an Adams View (or Adams Car) component that manages communication betwee ...

  4. IF函数

    语法:IF(logical_test,value_if_true,value_if_false) logical_test:表示计算结果为 TRUE 或 FALSE 的任意值或表达式 value_if ...

  5. XPages访问关系型数据库技术与最佳实践

    XPage 对于 Domino 开发人员的一大好处就是能够很方便和高效的访问关系型数据库.本文通过实例代码展现了在 XPage 中访问关系型数据库的具体步骤 , 同时讲解了一些在 XPage 中高效访 ...

  6. checkbox 多选框 :jquery之全选、全不选、反选

    javascriptjqueryselectAll [html] view plaincopy   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  7. 转:Ogre源码剖析 - 场景管理之Octree

    由于本人的引擎ProjectGaia服务于08年创新杯的游戏项目 – 3D太空游戏,所以理所应当加入Octree(八叉树 – 已经周宁学长发帖介绍过)场景管理器.参考了无数Octree的代码,发现还是 ...

  8. 敏捷开发与Scrum

    敏捷开发以用户的需求进化为核心,采用迭代.循序渐进的方法进行软件开发.在敏捷开发中,软件项目在构建初期被切分成多个子项目,各个子项目的成果都经过测试,具备可视.可集成和可运行使用的特征.换言之,就是把 ...

  9. CentOS vps下,安装xfce/KDE/GNOME桌面+vncserver进行远程管理

    CentOS vps下,安装xfce/KDE/GNOME桌面+vncserver进行远程管理 首先安装桌面环境,我选择的是xfce,轻量级桌面,小巧实用不占太多内存,(占用内存方面,xfce少于kde ...

  10. df看到的文件系统容量跟parted看到的分区容量差别较大的解决方法

    下午同事在自己的开发机上遇到题目说到的问题,它看到挂在到/dev/sda磁盘分区5上的ext4文件系统的容量显著小于该分区的大小 df看到的文件系统容量: #df -h /dev/sda5 Files ...