關於xml佈局中Fragment與 FrameLayout的理解
阿新 • • 發佈:2019-02-16
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".ActionTab_Activity" > <!-- 一定要tool:comtext --> <!--如果是fragment,一定要設定某fragment名字 如 android:name="com.cohere.fc.FragmentProcess" 表示啟動時先載入某fragment --> <Fragment android:id="@+id/main_titles" android:name="com.cohere.fc.FragmentProcess" android:layout_width="0px" android:layout_height="match_parent" android:layout_weight="1" /> <pre name="code" class="html"> <!-- FrameLayout是一個放置Fragment的容器 ,
不需要指定某個Fragment的名字,
可以通過FragmentManager動態新增刪除想放入其中的Fragment-->
<FrameLayout android:id="@+id/main_details" android:layout_width="0px" android:layout_height="match_parent" android:layout_weight="4" /></LinearLayout>
FrameLayout與Fragment標籤都是用來放Fragment的,區別是,Fragment標籤只能設定固定的Fragment,而FrameLayout中可以通過FragmentManager更換Fragment