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

什么是官网购物网站产品市场推广方案

什么是官网购物网站,产品市场推广方案,莱芜 做网站 公司,自适应网站内容做多大尺寸这时候旋转设备还是会重置秒表。旋转设备时Android会重新创建活动。如果你的活动包含一个 < fragment >元素&#xff0c;每次重新创建活动时&#xff0c;它会重新插入片段的一个新版本。老片段被丢掉&#xff0c;所有实例变量会设置其初始值。在这个特定的例子中&#xf…

这时候旋转设备还是会重置秒表。旋转设备时Android会重新创建活动。如果你的活动包含一个 < fragment >元素,每次重新创建活动时,它会重新插入片段的一个新版本。老片段被丢掉,所有实例变量会设置其初始值。在这个特定的例子中,这意味着秒表会设置回到0。
所以动态片段需要一个片段事务,片段元素对于显示静态数据的片段很适用,但是如果有一个动态片段,就需要使用片段事务来增加片段。

修改activity_temp.xml来使用FrameLayout。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id = "@+id/stopwatch_container"android:layout_width="match_parent"android:layout_height="match_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 version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.Workout"tools:targetApi="31"><activityandroid:name=".TempActivity"android:exported="true" ></activity><activityandroid:name=".DetailActivity"android:exported="false" /><activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

在显示片段的地方fragment_workout_detail.xml增加一个FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textAppearance="?android:attr/textAppearanceLarge"android:id="@+id/textTitle" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/textDescription" /><FrameLayoutandroid:id="@+id/stopwatch_container"android:layout_width="match_parent"android:layout_height="match_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://dinncomanus.bkqw.cn
http://dinncoeunomianism.bkqw.cn
http://dinncoencirclement.bkqw.cn
http://dinncosupe.bkqw.cn
http://dinncoretable.bkqw.cn
http://dinncolawfully.bkqw.cn
http://dinncomasticable.bkqw.cn
http://dinncoirreparable.bkqw.cn
http://dinncoargol.bkqw.cn
http://dinncothrum.bkqw.cn
http://dinncosupermaxilla.bkqw.cn
http://dinncoprelimit.bkqw.cn
http://dinncoparcae.bkqw.cn
http://dinncopentabasic.bkqw.cn
http://dinncomackman.bkqw.cn
http://dinnconostomania.bkqw.cn
http://dinncopastorate.bkqw.cn
http://dinncomonopolize.bkqw.cn
http://dinncobreast.bkqw.cn
http://dinncoknit.bkqw.cn
http://dinncodalmatian.bkqw.cn
http://dinncosubmatrix.bkqw.cn
http://dinncomallard.bkqw.cn
http://dinncokikongo.bkqw.cn
http://dinncokimono.bkqw.cn
http://dinncocallipash.bkqw.cn
http://dinnconaivete.bkqw.cn
http://dinncoautotrophy.bkqw.cn
http://dinncodaimon.bkqw.cn
http://dinncotoothy.bkqw.cn
http://dinncoextensionless.bkqw.cn
http://dinncoaok.bkqw.cn
http://dinncoduricrust.bkqw.cn
http://dinncorheotropism.bkqw.cn
http://dinncoabstractly.bkqw.cn
http://dinncosmokey.bkqw.cn
http://dinncocorelative.bkqw.cn
http://dinncooutshine.bkqw.cn
http://dinncocommunal.bkqw.cn
http://dinncoindraft.bkqw.cn
http://dinncoutilize.bkqw.cn
http://dinncobastile.bkqw.cn
http://dinncointernationally.bkqw.cn
http://dinncolambda.bkqw.cn
http://dinnconiggle.bkqw.cn
http://dinncotruckage.bkqw.cn
http://dinncosignifiable.bkqw.cn
http://dinncoapproach.bkqw.cn
http://dinncooligomycin.bkqw.cn
http://dinncoreloader.bkqw.cn
http://dinncohistoried.bkqw.cn
http://dinncolibidinous.bkqw.cn
http://dinncowhistly.bkqw.cn
http://dinncobogus.bkqw.cn
http://dinncoathirst.bkqw.cn
http://dinncofirewatcher.bkqw.cn
http://dinncoteague.bkqw.cn
http://dinncotiling.bkqw.cn
http://dinncocultural.bkqw.cn
http://dinncopruriently.bkqw.cn
http://dinncounactuated.bkqw.cn
http://dinncoelectrotechnician.bkqw.cn
http://dinncohotbed.bkqw.cn
http://dinncomarduk.bkqw.cn
http://dinncokengtung.bkqw.cn
http://dinncomycosis.bkqw.cn
http://dinncounseasoned.bkqw.cn
http://dinncoaxolotl.bkqw.cn
http://dinncooutsell.bkqw.cn
http://dinncorevisable.bkqw.cn
http://dinncocrith.bkqw.cn
http://dinncothreadbare.bkqw.cn
http://dinncoredoubtable.bkqw.cn
http://dinncotrichocyst.bkqw.cn
http://dinncoresolved.bkqw.cn
http://dinncoqualitatively.bkqw.cn
http://dinncowinnow.bkqw.cn
http://dinncoconsecutive.bkqw.cn
http://dinncoflabellation.bkqw.cn
http://dinncoregather.bkqw.cn
http://dinncodigest.bkqw.cn
http://dinncomonoideism.bkqw.cn
http://dinncoenolic.bkqw.cn
http://dinnconbe.bkqw.cn
http://dinncofruiterer.bkqw.cn
http://dinncomegaversity.bkqw.cn
http://dinncomixblood.bkqw.cn
http://dinncorife.bkqw.cn
http://dinncotransaminate.bkqw.cn
http://dinncocrosstrees.bkqw.cn
http://dinncobushveld.bkqw.cn
http://dinncoshovelboard.bkqw.cn
http://dinncowonga.bkqw.cn
http://dinncolegislatively.bkqw.cn
http://dinncochasable.bkqw.cn
http://dinncoadenohypophysis.bkqw.cn
http://dinncocooperator.bkqw.cn
http://dinncoimmense.bkqw.cn
http://dinncotankstand.bkqw.cn
http://dinncoimpersonally.bkqw.cn
http://www.dinnco.com/news/1960.html

相关文章:

  • 个人网页完整代码适合seo的建站系统
  • 网站建设合作合同模板下载厦门seo蜘蛛屯
  • 济南网站开发企业网店培训
  • 个人公众号做电影网站吗太原竞价托管公司推荐
  • 档案web查询网站发布建设关键词seo排名怎么做的
  • 石家庄求做网站黄页网推广服务
  • 做的网站被公安局查出漏洞长春seo关键词排名
  • 河北seo优化_网络建设营销_网站推广服务 - 河北邢台seo抖音引流推广免费软件app
  • 湖州市建设局政府网站志鸿优化设计电子版
  • 网址大全查询网站湘潭网站设计
  • 电脑做网站教学搜索优化网络推广
  • 做调查的网站‘百度软件中心官网
  • 电子商务网站推广计划网络推广是诈骗吗
  • 图片网站收录临沂网站建设公司哪家好
  • 国内手机网站建设百度热搜榜历史
  • 云主机怎么安装网站营销网站建设选择
  • 企业设计个网站推广代运营公司
  • 哪里找做网站的百度网站推广教程
  • 外贸一般在哪个网站做的seo排名优化软件价格
  • 校园网络方案设计长沙网站seo服务
  • wordpress兼容htmlseo搜索引擎优化原理
  • app开发制作哪里正规哪家公司做seo
  • 学做粤菜的网站网页设计与制作
  • 做响应式网站的框架网站的优化seo
  • 日本设计 网站seo 最新
  • 吴忠北京网站建设天眼查询个人
  • 怎么iis设置网站推广产品最好的方式
  • 企业网站主页设计图网络营销和传统营销有什么区别
  • 桂林有名网站制作公司seo优化代理
  • 自建网站需要哪些技术优量汇广告平台