Fragment的生命周期:
成都創(chuàng)新互聯(lián)公司服務(wù)項目包括祥符網(wǎng)站建設(shè)、祥符網(wǎng)站制作、祥符網(wǎng)頁制作以及祥符網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,祥符網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到祥符省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
Fragment正常情況下從創(chuàng)建到銷毀的生命周期回調(diào):onAttach(依附于宿主activity),onCreate(系統(tǒng)創(chuàng)建Fragment),onCreateView(創(chuàng)建布局文件),onActivityCreated(activity 的onCreate回調(diào)后會調(diào)用該生命周期方法),onStart(),onResume(),onPause(),onStop(),onDestroyView(),onDestroy(),onDetach()
旋轉(zhuǎn)屏幕時的生命周期:
2.?將手機屏幕向上,旋轉(zhuǎn)180度,不會觸發(fā)任何生命周期。
添加到Activity中:
<fragment
android:id="@+id/one_fragment"
android:name="com.cy.test.fragmentapplication.OneFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);//第一個參數(shù)是 ViewGroup,即應(yīng)該放置片段的位置,由資源 ID 指定,第二個參數(shù)是要添加的片段。
fragmentTransaction.commit();
DialogFragment:
拓展DialogFragment需要實現(xiàn)onCreateView或者onCreateDialog:
// 實現(xiàn)onCreateView
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.dialog_fragment_test1, container);
return inflate;
}
// 實現(xiàn)onCreateDialog
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
LayoutInflater inflater = Objects.requireNonNull(getActivity()).getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_fragment_test1, null));
return builder.create();
}
<!-- dialog_fragment_test1的布局文件 -->
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="50dp"
android:layout_marginTop="4dp"
android:text="測試。。。。巴拉巴拉巴拉巴拉巴拉。....巴拉。"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
分享標題:Fragment使用詳解
鏈接分享:http://jinyejixie.com/article22/ijgjjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、小程序開發(fā)、品牌網(wǎng)站設(shè)計、企業(yè)建站、網(wǎng)站設(shè)計、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)