当我尝试在 Eclipse 的图形布局中显示 android xml 文件时,我收到此消息:从 fragment 布局上下文菜单中选择预览布局。我按照说明右键单击布局 --> fragment 布局 --> 选择布局。但是,当我尝试选择我的布局(由于某种原因无法显示的文件)时,我收到此错误:“循环包含,无效”。我可以选择所有其他布局,例如 androids 预定义的 list_content。
我做错了什么?
这是我的 xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/example_id"
android:name="com.example.test.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是我的 java:
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
这是一个打印屏幕:
最佳答案
您应该在 fragment XML 项目中包含一个名称属性..例如:
android:name="com.example.news.ArticleListFragment"
...其中“ArticleListFragment”是您要使用的 fragment 类。完整 fragment 是:
<fragment android:name="com.example.news.ArticleListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
另请参阅:Fragments , 和 Creating a Fragment .
关于android - xml 中的单个 fragment 给出预览错误 : "Cyclic include, not valid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19119687/