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. PCI(Payment Card Industry)合规

     PCI-DSS(Payment Card Industry-Data Security Standard) 1.构建并维护安全的网络 2.保护持卡人数据 3.维护漏洞管理程序 4.执行严格的访问控制 ...

  3. django之创建站点之基本流程

    创建工程: 1.在D盘下创建一个文件夹名为djangoweb,切换到文件夹所在目录 C:\Administrator>d: D:\>cd d:\djangoweb 2.创建工程(成功没有提 ...

  4. topshelf 开发windows 服务资料

    官方配置 http://docs.topshelf-project.com/en/latest/configuration/config_api.html#service-start-modes to ...

  5. oracle初始化化表空间用户权限

    oracle单实例安装完毕,需要初始化表空间.用户.等信息.不积跬步,何以至千里! 用sys账户登录oracle数据库,以此来完成所有操作! 01.创建临时表空间 create temporary t ...

  6. Android实现中文汉字笔划(笔画)、中文拼音排序、英文排序

    发布时间:2018-11-16   技术:Android   概述 最近要做一个类似微信的,在登录界面选择国家地区的功能,微信有中文汉字笔画排序以及中文拼音排序等几种方式,如下所示: 简体中文 拼音排 ...

  7. 《Java设计模式》之模板方法模式

    模板方法模式是类的行为模式.准备一个抽象类.将部分逻辑以详细方法以及详细构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类能够以不同的方式实现这些抽象方法,从而对剩余的逻辑有 ...

  8. 【table】给table表格设置一个通用的css3样式(默认有斑马条纹)

    /* = 表格(默认有斑马条纹) ------------------------------------------ */ .data-table { margin: 10px 0; } .data ...

  9. asiHttpRequst 超时代码判断

    - (void)requestFailed:(ASIHTTPRequest *)request{ NSDictionary *userInfo = [request userInfo]; id del ...

  10. 使用IntelliJ IDEA 15和Maven创建Java Web项目

    转自:https://blog.csdn.net/myarrow/article/details/50824793博文链接!