android - xml 中的单个 fragment 给出预览错误 : "Cyclic include, not valid"

标签 android eclipse graphical-layout-editor

当我尝试在 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);
    }
}

这是一个打印屏幕:

Print screen of "Cyclic include, not valid" error

最佳答案

您应该在 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/

相关文章:

java - 使用正则表达式替换全部不替换完整结果

android - 在android中停止服务

java - 如何在关于对话框中添加构建 ID,

java - 如何使用转向功能来转向Finch机器人?

android - 为什么 Android Studio 设计器显示我的自定义 View 嵌套在自身内部,而它不是

Android 图形布局错误

android - 图形布局窗口上出现奇怪的 Eclipse ADT 错误

android - 如何在 Android XML 中创建固定高度的垂直线?

android surfaceview 在进入后台时崩溃

eclipse - 在哪里可以获得 Spring 工具套件的更新站点