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

16年百度对泛解析网站的惩罚广东网站建设类公司

16年百度对泛解析网站的惩罚,广东网站建设类公司,wordpress更新500错误,十大网游人气排行榜前言 fragment是从android3.0开始提出来的#xff0c;用来支持大屏幕设备的ui设计。通过将activity划分为多个fragment#xff0c;不仅提高了设计的灵活性#xff0c;而且可以在程序运行时改变它们的特征#xff0c;比如动态的修改#xff0c;替换已有的fragment等等。 fr…前言     fragment是从android3.0开始提出来的用来支持大屏幕设备的ui设计。通过将activity划分为多个fragment不仅提高了设计的灵活性而且可以在程序运行时改变它们的特征比如动态的修改替换已有的fragment等等。     fragment的角色是相当于activity中ui的一个子集或者说是activity中的一个模块可以通过组合多个fragment来构造一个多个面板的界面。由于fragment嵌入在activity中因此它的生命周期受到activity的影响一旦activity停掉它里面所有的fragment也都会被摧毁。     可以在activity的布局文件中通过声明fragment标签来填充它的布局同时也可以通过代码将它加到已经存在的ViewGroup中因为fragment布局实际上就是ViewGroup的子树。 新建一个Fragment     首先需要了解的是fragment的生命周期如下图所示 可以看出调用的先后顺序是 onCreate  这里可以用来初始化一些当fragment停掉时候你仍想保存的组件onCreateView  这里可以用来绘制fragment的用户界面因此必须返回一个viewonPause  当fragment被移走或者替换时调用可以在这里commit changes一般可以继承fragment类来创建自己的fragment同时亦有几个有用的fragment基类供我们继承 DialogFragment  也就是浮动在Activity上面的fragment这种对话框可以供用户返回便于管理是google推荐的做法。ListFragment  就是包含ListView的Fragment用来显示列表等。PreferenceFragment  可以用来显示用户选项的设置。一般来说要创建Fragment第一步就是创建一个Fragment的子类并在onCrateView方法中填充布局 public static class ExampleFragment extends Fragment {Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragment//resourceID,ViewGroup, whether the inflated layout should be //attached to the ViewGroup during inflationreturn inflater.inflate(R.layout.example_fragment, container, false);} } 第二步就是将fragment添加到activity中,可以在activity的布局文件中声明,如: ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:orientationhorizontalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentfragment android:namecom.example.news.ArticleListFragmentandroid:idid/listandroid:layout_weight1android:layout_width0dpandroid:layout_heightmatch_parent /fragment android:namecom.example.news.ArticleReaderFragmentandroid:idid/viewerandroid:layout_weight2android:layout_width0dpandroid:layout_heightmatch_parent / /LinearLayout 这样一来,当创建activity的布局时,就会初始化每一个fragment,并且调用它们的onCreateView方法,获取fragment的布局,然后插入到ViewGroup下面。 除了使用布局文件之外还可以用程序进行添加 FragmentManager fragmentManager getFragmentManager() FragmentTransaction fragmentTransaction fragmentManager.beginTransaction(); ExampleFragment fragment new ExampleFragment(); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); 前两行用来获取碎片事务FragmentTransaction后三行用来添加一个fragmentadd方法的第一个参数是要放置的ViewGroup第二个参数是要添加的fragment。 Fragment的管理 通过fragmentManager可以做一下事情 获取fragment通过findFragmentById或者findFragmentByTag将Fragment从栈中移除通过popBackStack方法为back stack注册监听器相信这里的细节还有很多暂时先不介绍。 Fragment的事务     fragment的一大亮点就是可以动态增加删除替换fragment而这是通过fragmentTransaction来实现的。一旦获取了事务的实例就可以通过调用addremovereplace方法完成上述功能接下来通过commit方法提交事务就可以了。 // Create new fragment and transaction Fragment newFragment new ExampleFragment(); FragmentTransaction transaction getFragmentManager().beginTransaction();// Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null);// Commit the transaction transaction.commit();     除此之外还可以调用addToBackStack方法将fragment添加到back stack中用户按下返回键时就会跳到back stack顶部的fragment。调不调用它的区别在于如果没有它fragment被remove后就彻底销毁了再也不能恢复如果调用了它fragment就不会销毁而是stop这样就可以恢复因为fragment的状态都被保存在了back stack上面。     commit方法的作用是调度到activity的主线程中执行并且事务的提交必须要在onSaveInstanceState之前。 和Activity的通信     fragment也是可以和它所在的activity通信的比如可以通过getActivity()方法得到所在的activity相应的activity也可以调用FragmentManager的findFragmentById方法获取某一个fragment的引用。     有时候需要在fragment和activity之间共享事件如activity有一个fragment是用来显示文章的列表的当用户点击了某一项activity需要检测到这个事件同时更改另一个fragment从而显示出相应的文章内容。这时可以这么做在fragment中定义事件监听的接口然后让activity实现这个接口。然后这个fragment就可以调用接口中的某些方法来通知activity了。fragment中可以在onAttach里面将activity强制转化为接口的实现类从而确保能成功调用接口中的方法。 public static class FragmentA extends ListFragment {OnArticleSelectedListener mListener;...// Container Activity must implement this interfacepublic interface OnArticleSelectedListener {public void onArticleSelected(Uri articleUri);}...Overridepublic void onAttach(Activity activity) {super.onAttach(activity);try {mListener (OnArticleSelectedListener) activity;} catch (ClassCastException e) {throw new ClassCastException(activity.toString() must implement OnArticleSelectedListener);}}...Overridepublic void onListItemClick(ListView l, View v, int position, long id) {// Append the clicked items row ID with the content provider UriUri noteUri ContentUris.withAppendedId(ArticleColumns.CONTENT_URI, id);// Send the event and Uri to the host activitymListener.onArticleSelected(noteUri);}... } 例子    该例子来源于api demo用到了很典型的两个fragment一个是TitlesFragment用来显示一个列表另一个是DetailsFragment用来显示选中item的详细信息。此外该程序还考虑到了屏幕的横竖屏问题如果是竖屏的话没有足够的地方显示第二个Fragment就单独启动一个Activity。源码如下 /*** Demonstration of using fragments to implement different activity layouts.* This sample provides a different layout (and activity flow) when run in* landscape.*/ public class FragmentLayout extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.fragment_layout);}/*** This is a secondary activity, to show what the user has selected* when the screen is not large enough to show it all in one activity.*/public static class DetailsActivity extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);if (getResources().getConfiguration().orientation Configuration.ORIENTATION_LANDSCAPE) {// If the screen is now in landscape mode, we can show the// dialog in-line with the list so we dont need this activity.finish();return;}if (savedInstanceState null) {// During initial setup, plug in the details fragment.DetailsFragment details new DetailsFragment();details.setArguments(getIntent().getExtras());getFragmentManager().beginTransaction().add(android.R.id.content, details).commit();}}}/*** This is the top-level fragment, showing a list of items that the* user can pick. Upon picking an item, it takes care of displaying the* data to the user as appropriate based on the currrent UI layout.*/public static class TitlesFragment extends ListFragment {boolean mDualPane;int mCurCheckPosition 0;Overridepublic void onActivityCreated(Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);// Populate list with our static array of titles.setListAdapter(new ArrayAdapterString(getActivity(),android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));// Check to see if we have a frame in which to embed the details// fragment directly in the containing UI.View detailsFrame getActivity().findViewById(R.id.details);mDualPane detailsFrame ! null detailsFrame.getVisibility() View.VISIBLE;if (savedInstanceState ! null) {// Restore last state for checked position.mCurCheckPosition savedInstanceState.getInt(curChoice, 0);}if (mDualPane) {// In dual-pane mode, the list view highlights the selected item.getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);// Make sure our UI is in the correct state.showDetails(mCurCheckPosition);}}Overridepublic void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState(outState);outState.putInt(curChoice, mCurCheckPosition);}Overridepublic void onListItemClick(ListView l, View v, int position, long id) {showDetails(position);}/*** Helper function to show the details of a selected item, either by* displaying a fragment in-place in the current UI, or starting a* whole new activity in which it is displayed.*/void showDetails(int index) {mCurCheckPosition index;if (mDualPane) {// We can display everything in-place with fragments, so update// the list to highlight the selected item and show the data.getListView().setItemChecked(index, true);// Check what fragment is currently shown, replace if needed.DetailsFragment details (DetailsFragment)getFragmentManager().findFragmentById(R.id.details);if (details null || details.getShownIndex() ! index) {// Make new fragment to show this selection.details DetailsFragment.newInstance(index);// Execute a transaction, replacing any existing fragment// with this one inside the frame.FragmentTransaction ft getFragmentManager().beginTransaction();if (index 0) {ft.replace(R.id.details, details);} else {ft.replace(R.id.a_item, details);}ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);ft.commit();}} else {// Otherwise we need to launch a new activity to display// the dialog fragment with selected text.Intent intent new Intent();intent.setClass(getActivity(), DetailsActivity.class);intent.putExtra(index, index);startActivity(intent);}}}/*** This is the secondary fragment, displaying the details of a particular* item.*/public static class DetailsFragment extends Fragment {/*** Create a new instance of DetailsFragment, initialized to* show the text at index.*/public static DetailsFragment newInstance(int index) {DetailsFragment f new DetailsFragment();// Supply index input as an argument.Bundle args new Bundle();args.putInt(index, index);f.setArguments(args);return f;}public int getShownIndex() {return getArguments().getInt(index, 0);}Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {if (container null) {// We have different layouts, and in one of them this// fragments containing frame doesnt exist. The fragment// may still be created from its saved state, but there is// no reason to try to create its view hierarchy because it// wont be displayed. Note this is not needed -- we could// just run the code below, where we would create and return// the view hierarchy; it would just never be used.return null;}ScrollView scroller new ScrollView(getActivity());TextView text new TextView(getActivity());int padding (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4, getActivity().getResources().getDisplayMetrics());text.setPadding(padding, padding, padding, padding);scroller.addView(text);text.setText(Shakespeare.DIALOGUE[getShownIndex()]);return scroller;}}} View Code   转载于:https://www.cnblogs.com/cubika/p/3177782.html
http://wiki.neutronadmin.com/news/38230/

相关文章:

  • 具有品牌的做pc端网站打开网站乱码怎么做
  • 网页制作与网站建设策划书案例微餐饮网站建设用途
  • 烟台H5网站设计公司莱特币做空国外网站
  • 国内网站制作欣赏网站建设公司销售技巧
  • 如何自己创建一个网址seo发外链的网站
  • 润滑油 东莞网站建设网站快速备案被退回的几种原因分析
  • 东莞seo建站排名软文推广是什么意思
  • 扬中网站建设策划朋友圈广告代理商官网
  • 南阳做网站推广建一个网页需要多少钱
  • 北京飞雨网站建设公司wordpress dokan
  • 查外链网站wordpress5.2自动保存
  • 网站开发销售单页展示网站
  • 商品网站建设实验记录公司名字大全 必过
  • 网站的百度推广怎么做嵌入式软件开发工程师工作内容
  • 手机网站页面范例企业宣传册ppt模板
  • 免费制作动画网站成化区建设局网站
  • 全平台开发网站及app博客网站开发背景
  • 山东川畅信息技术有限公司网站建设网站怎么加代码
  • 郑州市建设局官方网站wordpress php
  • 网站快照历史各学院二级网站建设通报
  • 网站报价单申请网页要多少钱
  • 重庆网站运营购物网站功能
  • 网站中 点击出现登录框怎么做网站上怎么做弹幕效果
  • 网站搭建类型开发工程师是什么
  • 建一个网站 服务器机房托管价格暴雪手游
  • 网站域名查询地址慧算账代理记账公司
  • 天津电商网站制作网络服务器忙请稍后重试怎么办
  • 携程网站联盟如何在国外网站开发新客人
  • 高新技术企业申报网站网站带薪歌手都要怎样做呀
  • 常州网站开发培训软件合集软件资料2023