静态fragment的xml布局写法:
<
RelativeLayout
xmlns:android
="http://schemas.android.com/apk/res/android"
xmlns:tools
="http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<
fragment
android:id
="@+id/
fragment_left_newstitle
"
以便于在代码中操作该碎片
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:name
="com.qf.fragment.
LeftFragment
"
/>
自定义的
Fragment
子类的全限定名 (
包名加类名)
,
在该类中的
onCre
ateView
方法中,指定使用哪一个碎片的布局文件
</
RelativeLayout
>
-----------------------------------------------------
静态代码实例:
xml文件:
<
RelativeLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
xmlns:tools
=
"http://schemas.android.com/tools"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:paddingBottom
=
"@dimen/activity_vertical_margin"
android:paddingLeft
=
"@dimen/activity_horizontal_margin"
android:paddingRight
=
"@dimen/activity_horizontal_margin"
android:paddingTop
=
"@dimen/activity_vertical_margin"
tools:context
=
".MainActivity"
>
<
fragment
android:id
=
"@+id/fragmentId"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:name
=
"com.mrl.fragment.StaticFragment"
/>
</
RelativeLayout
>