3 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
經(jīng)過長(zhǎng)時(shí)間的調(diào)試,我已解決此問題。(盡管我仍然無法解釋原因)。我將財(cái)產(chǎn)更改android:name為class。(盡管在Android Document上,他們說這些屬性是相同的,但是可以正常使用!?。。?/p>
因此,它應(yīng)從:
android:name="com.fragment.NavigationDrawerFragment"
至
class = "com.fragment.NavigationDrawerFragment"
因此,新布局應(yīng)為:
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
class = "com.fragment.NavigationDrawerFragment" />
希望這個(gè)幫助:)

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
我無法使用提供的答案解決問題。最后我改變了這個(gè):
<fragment
android:id="@+id/fragment_food_image_gallery"
android:name="ir.smartrestaurant.ui.fragment.ImageGalleryFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout="@layout/fragment_image_gallery"
tools:layout="@layout/fragment_image_gallery" />
對(duì)此:
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="200dp" />
,
private void showGallery() {
ImageGalleryFragment fragment = new ImageGalleryFragment()
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
}
而且有效。
如果在片段中使用它,請(qǐng)使用getChildFragmentManager而不是getSupportFragmentManager。

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
我遇到了同樣的問題,問題,嘗試了該線程中的所有答案,但無濟(jì)于事。我的解決方案是,我沒有在Activity XML中添加ID。我認(rèn)為這并不重要,但確實(shí)如此。
因此,在活動(dòng)XML中,我有:
<fragment
android:name="com.covle.hellocarson.SomeFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
但是應(yīng)該有:
<fragment
android:id="@+id/some_fragment"
android:name="com.covle.hellocarson.SomeFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
如果有人樂于對(duì)這是為什么發(fā)表評(píng)論,我想向其他人說,我希望這會(huì)有所幫助。
- 3 回答
- 0 關(guān)注
- 621 瀏覽
添加回答
舉報(bào)