如何从 XML 定义片段的布局?
我正在尝试以与定义视图布局相同的方式在 XML 中定义片段的布局。
这可能吗?我尝试了几件事,但似乎都不起作用。
我的活动布局如下所示(主.xml):
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="full.lommeregner.Lommeregnerrv2Activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lommeregnerv2">
</fragment>
</ListView>
现在,由于我不是通过原始Java代码生成布局的忠实粉丝,因此我尝试按如下方式定义我的片段(fragment_lommeregner.xml):
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="full.lommeregner.Lommeregnerrv2Activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lommeregnerv2">
<!-- my content was located here (some textviews, buttons and so on). -->
</fragment>
我做错了什么吗?如何通过 XML 定义片段的布局?