【发布时间】:2012-03-16 06:45:43
【问题描述】:
我正在尝试以与定义视图布局相同的方式在 XML 中定义片段的布局。
这可能吗?我尝试了几件事,但似乎都没有工作。
我的活动布局如下(main.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 定义片段的布局?
【问题讨论】: