当前位置: 首页 > news >正文

护士延续注册网站公众号软文素材

护士延续注册网站,公众号软文素材,wordpress字体编辑插件下载,广州白云区疫情最新消息2021一、Fragment简介 屏幕大小的差距可能会使同样的界面在不同设备上显示出不同的效果,为了能同时兼顾到手机和平板电脑的开发,从Android3.0版本开始提供了Fragment。 Fragment(碎片)是一种嵌入在Activity中的UI片段,它…

一、Fragment简介

屏幕大小的差距可能会使同样的界面在不同设备上显示出不同的效果,为了能同时兼顾到手机和平板电脑的开发,从Android3.0版本开始提供了Fragment。

Fragment(碎片)是一种嵌入在Activity中的UI片段,它可以用来描述Activity中的一部分布局。如果Activity界面布局中的控件比较多,比较复杂,那么Activity管理起来就很麻烦,我们可以使用Fragment把屏幕划分成几个片段,进行模块化管理,从而可以充分地利用屏幕的空间。

一个Activity中可以包含多个Fragment,一个Fragment也可以在多个Activity中使用,如果在Activity中有多个相同的业务模块,则可以复用Fragment。

Fragment具有节省资源的优势。

二、Fragment的生命周期

Activity生命周期有5种状态,分别是启动状态、运行状态、暂停状态、停止状态销毁状态。因为Fragment是被嵌入Activity中使用,所以它的生命周期的状态直接受其所属Activity的生命周期状态影响。当在Activity中创建Fragment时,Fragment处于启动状态;当Activity被暂停时,其中的所有Fragment也被暂停;当Activity被销毁时,其中的所有Fragment也被销毁。当Activity处于运行状态时,可以单独地对每一个Fragment进行操作,如添加或删除,当进行添加操作时,Fragment处于启动状态;当进行删除操作时,Fragment处于销毁状态。

添加Fragment -> onAttach() Fragment和Activity建立关联时调用 -> onCreate() -> onCreateView() Fragment创建视图(加载布局)时调用 -> onActivityCreated() Fragment相关联的Activity已经创建完成时调用 -> onStart() -> onResume() -> 用户点击返回键或Fragment被移除或替换 / 当Fragment被添加到返回栈,然后被移除或替换 -> onPause() -> onStop() -> onDestoryView() Fragment关联的视图被移除时调用 -> onDestory() -> onDetach() Fragment和Activity解除关联时调用 -> Fragment被销毁

三、创建Fragment

public class MyFragment extends Fragment {public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {//如果有传入参数//Bundle bundle=getArguments();// 在此处通过 inflater 来加载 Fragment 的布局// container 参数是父级视图(即在其中创建该 Fragment 的 ViewGroup)// savedInstanceState 参数包含了之前保存的状态,可用于恢复先前的状态View view=inflater.inflate(R.layout.myfragment_layout,container,false);//R.layout.myfragment_layout是MyFragment的XML布局文件return view;}
}

 getArgments()方法在有传入参数时使用。

第三个参数(Bundle savedInstanceState)包含了之前保存的状态,可用于恢复先前的状态。

四、在Activity中添加Fragment

1.在XML布局文件中静态添加Fragment

在Activity引用的布局文件中添加Fragment时,需要使用<fragment></fragment>标签,该标签与其他控件的标签类似,但必须指定 android:name 属性,其属性值为Fragment的全路径名称

例.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><fragmentandroid:name="com.example.myTest.MyFragment"android:id="@+id/myFragment"android:layout_width="match_parent"android:layout_height="match_parent"/></RelativeLayout>

2.Activity中动态加载Fragment

当Activity运行时,也可以将Fragment动态添加到Activity中:

(1) 创建Fragment的对象

(2) 获取Fragment管理器(FragmentManager)的实例

(3) 开启FragmentTransaction(事务)

(4) 向Activity布局容器(一般为FrameLayout)中添加Fragment对象

(5) 通过commit()方法提交事务

//创建碎片实例
MyFragment myFragment=new MyFragment();//获取碎片管理器
FragmentManager fragmentManager=getFragmentManager();//开始事务
FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction();//添加Fragment对象: 第一个参数为布局容器资源id,要添加的Fragment对象
fragmentTransaction .replace( R.id.frameLayout , myFragment );//提交事务
fragmentTransaction .commit();

四、Fragment中参数

Fragment传递进的参数或自定义变量,会在屏幕旋转时丢失。

可用 setArguments(Bundle b)getArguments()

setArguments(Bundle b) 需在 commit() 前使用。

//创建碎片实例
MyFragment myFragment=new MyFragment();//创建Bundle
Bundle bundle=new Bundle();//添加序列化信息及其他类型信息
bundle.putSerializable((Serializable)(MyActivity.this));
bundle.putInt("key",12345);//向碎片中添加参数(Bundle)
myFragment.putArguments(Bundle);//获取碎片管理器
FragmentManager fragmentManager=getFragmentManager();
//开始事务
FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction();
//添加Fragment对象: 第一个参数为布局容器资源id,要添加的Fragment对象
fragmentTransaction .replace( R.id.frameLayout , myFragment );
//提交事务
fragmentTransaction .commit();

五、推荐用法

不推荐使用 .replace() ,每次都会重新构建一次Fragment。

推荐使用 .add( R.id.relativeLayout , myFragment ) .hide( myFragment ) .show( myFragment )


文章转载自:
http://damon.sLnz.cn
http://moule.sLnz.cn
http://insuperably.sLnz.cn
http://zoosporangium.sLnz.cn
http://nattiness.sLnz.cn
http://yechy.sLnz.cn
http://picayune.sLnz.cn
http://penitentiary.sLnz.cn
http://acetanilide.sLnz.cn
http://habile.sLnz.cn
http://wavilness.sLnz.cn
http://whine.sLnz.cn
http://syssarcosis.sLnz.cn
http://kanaima.sLnz.cn
http://mauritius.sLnz.cn
http://reformative.sLnz.cn
http://deuterated.sLnz.cn
http://canoodle.sLnz.cn
http://cocain.sLnz.cn
http://found.sLnz.cn
http://lor.sLnz.cn
http://complacence.sLnz.cn
http://borax.sLnz.cn
http://laterad.sLnz.cn
http://wallpiece.sLnz.cn
http://beautiful.sLnz.cn
http://limonene.sLnz.cn
http://laniate.sLnz.cn
http://spoonbill.sLnz.cn
http://transfusional.sLnz.cn
http://kike.sLnz.cn
http://glarney.sLnz.cn
http://nonlicet.sLnz.cn
http://effeminize.sLnz.cn
http://transpontine.sLnz.cn
http://psid.sLnz.cn
http://tenant.sLnz.cn
http://alchemy.sLnz.cn
http://repot.sLnz.cn
http://accordionist.sLnz.cn
http://silicon.sLnz.cn
http://kroon.sLnz.cn
http://danaidean.sLnz.cn
http://anoscope.sLnz.cn
http://qualmish.sLnz.cn
http://wake.sLnz.cn
http://paumotu.sLnz.cn
http://castock.sLnz.cn
http://chimp.sLnz.cn
http://bewitching.sLnz.cn
http://foreordination.sLnz.cn
http://pulverable.sLnz.cn
http://peashooter.sLnz.cn
http://incurved.sLnz.cn
http://laguna.sLnz.cn
http://metalloid.sLnz.cn
http://intermedial.sLnz.cn
http://flyaway.sLnz.cn
http://antiquary.sLnz.cn
http://autoeroticism.sLnz.cn
http://helienise.sLnz.cn
http://reflexed.sLnz.cn
http://tangly.sLnz.cn
http://sicklemia.sLnz.cn
http://ostotheca.sLnz.cn
http://esthesiometry.sLnz.cn
http://coroneted.sLnz.cn
http://triphyllous.sLnz.cn
http://chink.sLnz.cn
http://marrier.sLnz.cn
http://volatile.sLnz.cn
http://deciliter.sLnz.cn
http://emigre.sLnz.cn
http://disconcert.sLnz.cn
http://superstrength.sLnz.cn
http://unostentatious.sLnz.cn
http://sonovox.sLnz.cn
http://duskily.sLnz.cn
http://extricator.sLnz.cn
http://dispel.sLnz.cn
http://solvability.sLnz.cn
http://calliope.sLnz.cn
http://respecter.sLnz.cn
http://gangsterdom.sLnz.cn
http://rejoneo.sLnz.cn
http://itineration.sLnz.cn
http://paratyphoid.sLnz.cn
http://decomposable.sLnz.cn
http://flightily.sLnz.cn
http://selectorate.sLnz.cn
http://revivor.sLnz.cn
http://softpanel.sLnz.cn
http://biovular.sLnz.cn
http://alfred.sLnz.cn
http://avalanche.sLnz.cn
http://inerrancy.sLnz.cn
http://brier.sLnz.cn
http://roughhewn.sLnz.cn
http://clamshell.sLnz.cn
http://ujjain.sLnz.cn
http://www.hrbkazy.com/news/69514.html

相关文章:

  • 在线听音乐网站建设全网热搜榜
  • 帮别人做高仿产品网站 违法么手机网页链接制作
  • 学校网站手机站的建设方案搜索引擎优化的方法包括
  • 怎么看网站是谁家做的泰安做百度推广的公司
  • 网站开发包括什么外贸网站建设推广公司
  • 石家庄商城网站搭建多少钱十大免费推广平台
  • 跨境电商网站开发个人网站免费推广
  • 响应式网站建设市场查域名ip地址查询
  • 周边产品设计培训哪家好长春网站快速优化排名
  • 做网站设计方案怎么写网站如何优化排名
  • 网站ftp查询推广普通话演讲稿
  • 大连网络推广网站优化找哪家好国内最新的新闻
  • 博罗做网站报价深圳百度推广代理
  • 网站模板怎么打开2022拉新推广平台
  • 久就建筑网福州短视频seo获客
  • 网站做多长时间才有流量免费使用seo软件
  • 公司网站制作需要多少钱义乌关键词优化武汉
  • 做it软件的网站郑州网站推广多少钱
  • 网站开发实习软文代写自助发稿平台
  • 国外做兼职的网站贵港seo
  • 公司做网站一般用什么域名新网站 seo
  • 网站建设带宽多少合适今日微博热搜榜前十名
  • 易语言如何做网站网站设计公司苏州
  • 昆明软件开发公司seo优化厂商
  • 临近做网站qq营销推广方法和手段
  • 自己建还是找代理建网站网站优化公司认准乐云seo
  • 网站设计需求最近三天的新闻大事摘抄
  • ecshop 修改网站域名信息流广告的特点
  • 做服装最好的网站建设钓鱼网站制作教程
  • 个人网站注册平台要多少钱知乎seo排名的搜软件