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. Struts2学习笔记四:深入拦截器

    一:拦截器的工作原理 拦截器的执行过程可以类比filter过滤器,ActionInvocation实例执行过程中,先执行action实例上引用的拦截器们,然后才执行action实例处理请求,返回res ...

  2. J4架构应用过程中出现的问题与解决摘录

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6369346.html sendRedirect()的页面不能用EL表达式获取参数:因为是新的request.E ...

  3. Newifi2(D1) 刷入pb-boot和breed的记录

    今天要给一个newifi d1刷系统时发现居然还是原厂的uboot, 使用uboot刷入rom时会进行校验拦截第三方的rom. 之前有刷过这个设备的, 但是已经完全记不清怎么处理的了. 查了一下, 这 ...

  4. KVM安装和配置

    [未验证部分] kvm安装前检查 # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 ca ...

  5. 在QTableView中某列中添加Button的导致滚动条滚动的时候消失的问题

    之前在项目上需要在表格中加入Button是按照以下两个文章的做法: http://www.cnblogs.com/li-peng/p/3961843.html http://www.cnblogs.c ...

  6. 解决PHP Fatal error mysql_connect() mysql_query()的问题

    单独安装Apache.PHP.Mysql在进行开发调试的时候经常会遇到各种问题,好多人说比appserv或者xampp集成安装包麻烦,其实不然,单独配置可以更深入的了解每个部件分别是怎么运行的,深入理 ...

  7. HDUOJ----Coin Change

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. 转 windows查看端口占用命令

    转自  http://www.cnblogs.com/allenblogs/archive/2010/06/25/1765055.html 开始--运行--cmd 进入命令提示符 输入netstat ...

  9. 进阶之路(基础篇) - 022 Arduino Leonardo 中文介绍(摘抄)

    本文摘抄:http://www.arduino.cn/thread-1205-1-1.html 概述Arduino Leonardo是基于ATmega32u4一个微控制器板.它有20个数字输入/输出引 ...

  10. 新浪安装weiphp2.0的方法

    请安装此网页的方法来安装: https://coding.net/u/idoubi666/p/weiphp-sae/git