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

兰州网站推广优化律师推广网站排名

兰州网站推广优化,律师推广网站排名,网站建设资料清单,网站开发计入会计 什么科目这时候旋转设备还是会重置秒表。旋转设备时Android会重新创建活动。如果你的活动包含一个 fragment 元素#xff0c;每次重新创建活动时#xff0c;它会重新插入片段的一个新版本。老片段被丢掉#xff0c;所有实例变量会设置其初始值。在这个特定的例子中#xf…这时候旋转设备还是会重置秒表。旋转设备时Android会重新创建活动。如果你的活动包含一个 fragment 元素每次重新创建活动时它会重新插入片段的一个新版本。老片段被丢掉所有实例变量会设置其初始值。在这个特定的例子中这意味着秒表会设置回到0。 所以动态片段需要一个片段事务片段元素对于显示静态数据的片段很适用但是如果有一个动态片段就需要使用片段事务来增加片段。 修改activity_temp.xml来使用FrameLayout。 ?xml version1.0 encodingutf-8? FrameLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:id id/stopwatch_containerandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent /FrameLayout为TempActivity.java增加一个片段事务。 它将StopwatchFragment增加到TempActivity。 package com.hfad.workout;import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; import android.os.Bundle;public class TempActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_temp);if (savedInstanceState null) {StopwatchFragment stopwatch new StopwatchFragment();FragmentTransaction ft getSupportFragmentManager().beginTransaction();ft.add(R.id.stopwatch_container, stopwatch);ft.addToBackStack(null);ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);ft.commit();}} }如此运行应用后秒表就能像之前一样正常工作。 为WorkoutDetailFragment增加秒表 修改AndroidManifest.xml的启动应用 ?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsapplicationandroid:allowBackuptrueandroid:dataExtractionRulesxml/data_extraction_rulesandroid:fullBackupContentxml/backup_rulesandroid:iconmipmap/ic_launcherandroid:labelstring/app_nameandroid:roundIconmipmap/ic_launcher_roundandroid:supportsRtltrueandroid:themestyle/Theme.Workouttools:targetApi31activityandroid:name.TempActivityandroid:exportedtrue /activityactivityandroid:name.DetailActivityandroid:exportedfalse /activityandroid:name.MainActivityandroid:exportedtrueintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activity/application/manifest在显示片段的地方fragment_workout_detail.xml增加一个FrameLayout ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalTextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textAppearance?android:attr/textAppearanceLargeandroid:idid/textTitle /TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/textDescription /FrameLayoutandroid:idid/stopwatch_containerandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent //LinearLayout要在一个片段中使用片段事务时使用的代码基本相同有一个重要的区别就是 片段没有一个名为getSupportFragmentManager的方法下面这行代码需要修改 FragmentTransaction ft getSupportFragmentManager().beginTransaction();创建getFragmentManager在后退堆栈创建额外的事务。 getFragmentManager方法会得到与片段父活动相关联的片段管理器。使用这个片段管理器创建的所有事务片段事务会分别作为一个单独的事务增加到后退堆栈。 假设用户单击了一个训练项目会显示这个训练项目的详细信息以及秒表如果用户再单击后退按钮他们可能希望屏幕回到选择训练项目之前的状态。但是后退按钮只是弹出后退堆栈中的最后一个事务。这说明如果我们创建两个事务来增加训练项目个秒表用户单击后退按钮时只会删除秒表。他们必须再次单击后退按钮才能删除训练项目的详细信息。 使用getChildFragmentManager()创建嵌套事务 getChildFragmentManager方法会得到与片段的父片段关联的片段管理器。使用这个片段管理器创建的所有片段事务都会增加到父片段事务的后退堆栈而不是增加为一个单独的事务。 用户单击一个训练项目时还是会显示WorkoutDetailFragment和StopwatchFragment不过用户单击后退按钮时行为会有所不同。由于这两个事务是嵌套的所以用户按下后退按钮时两个事务都会从后退堆栈弹出。用户按下一次后退按钮训练项目详细信息和秒表都将删除。 把getChildFragmentManager()片段事务代码增加到WorkoutDetailFragment.java package com.hfad.workout;import android.os.Bundle;import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction;import android.os.PersistableBundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;public class WorkoutDetailFragment extends Fragment {//用来表示用户选择的训练项目的IDprivate long workoutId;Override//Android需要这个片段的布局时会调用这个方法public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// 这会告诉Android这个片段使用哪个布局return inflater.inflate(R.layout.fragment_workout_detail, container, false);}Overridepublic void onCreate(Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);if (savedInstanceState ! null){workoutId savedInstanceState.getLong(workoutId);}else{StopwatchFragment stopwatch new StopwatchFragment();FragmentTransaction ft getChildFragmentManager().beginTransaction();ft.add(R.id.stopwatch_container, stopwatch);ft.addToBackStack(null);ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);ft.commit();}}public void onStart() {super.onStart();//得到片段的根视图然后使用这个根视图得到两个文本视图的引用View view getView();if (view ! null) {TextView title (TextView) view.findViewById(R.id.textTitle);Workout workout Workout.workouts[(int)workoutId];title.setText(workout.getName());TextView description (TextView) view.findViewById(R.id.textDescription);description.setText(workout.getDescription());}}public void setWorkoutId(long id) {this.workoutId id;}Overridepublic void onSaveInstanceState(NonNull Bundle outState) {super.onSaveInstanceState(outState);outState.putLong(workoutId, workoutId);} }如此大功告成。
http://www.w-s-a.com/news/269420/

相关文章:

  • 杭州网站建设咨询蓝韵网络聊城有制作网站的吗
  • 网站开发注意的事项深圳企业网站
  • 哈尔滨网站制作哪里专业网站建设维护有哪些内容
  • 花的网站建设规划书网络营销培训
  • 又拍云wordpress全站cdn无锡做网站品牌公司
  • 计算机网络工程网站建设黄石建设信息网站
  • 旅游网站开发毕业设计开题报告青岛网站建设服务公司
  • 人员调动在网站上怎么做网站开发课程意见和建议
  • 卓训网是个什么网站wordpress命令执行时间
  • 网站建设需要做哪些工作网片焊接
  • 网站优化方案dedecms win8风格网站模板
  • 企业如何制作网站管理系统慈溪住房和城乡建设部网站
  • 青岛网站建设有哪些公司区块链网站开发价格
  • 怎么设置网站的logo微信公众号的h5网站开发6
  • 粉色的网站绍兴市建设局网站
  • 个人网站的基本风格是wordpress 模板选择
  • 南昌专业做网站公司有哪些广州市住房城乡建设部门户网站
  • 福州网站建设团队淘宝联盟网站怎么建设
  • 福州企业网站建站模板国内黑色风格的网站
  • 好看的网站首页设计android移动开发
  • 域名注册完成后如何做网站域名 删除 wordpress
  • wordpress xml导入大小东莞seo优化方案
  • 网站建设效益网站销售怎么做的
  • 利用网站空间做代理设计方案的格式范文
  • 无锡建设工程质量监督网站遵义做手机网站建设
  • 衡阳商城网站制作ps做网站首页规范尺寸
  • 微信网站应用开发营销推广的方案
  • 广州做网站商城的公司制作一个app的完整流程
  • 湖南城乡建设厅网站163注册企业邮箱
  • 做网站怎么调整图片间距织梦做的网站如何去掉index