java我的片段不会显示在我的活动中
我不熟悉安卓开发,也不熟悉这些片段
因此,我创建了6个xml文件,试图将其作为片段导入到活动中,我已经按照Google的说明一步一步地完成了所有操作,但是片段不会显示在我的活动菜单中
活动菜单。xml文件
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:orientation="horizontal"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent">
<fragment 安卓:name="com.grig.alexios.pdaapplication.BeerMenuFragment"
安卓:id="@+id/headlines_fragment"
安卓:layout_weight="1"
安卓:layout_width="0dp"
安卓:layout_height="match_parent" />
<fragment 安卓:name="com.grig.alexios.pdaapplication.GinMenuFragment"
安卓:id="@+id/article_fragment"
安卓:layout_weight="2"
安卓:layout_width="0dp"
安卓:layout_height="match_parent" />
</LinearLayout>
月经活跃。阶级
package com.grig.alexios.pdaapplication;
import 安卓.support.v4.app.FragmentActivity;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
public class MenuActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
}
编辑
片段示例
金丝分裂
package com.grig.alexios.pdaapplication;
import 安卓.os.Bundle;
import 安卓.support.v4.app.Fragment;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
public class GinMenuFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.gin, container, false);
}
}
# 1 楼答案
你需要一个碎片管理器来显示碎片。您可以使用FragmentManager的事务更改片段
在这里阅读有关FragmentManager的更多信息:https://developer.android.com/reference/android/app/FragmentManager.html
# 2 楼答案
我已经测试了你的代码,它运行正常
好吧,这会管用的
活动菜单。xml
以及内在的MenuActivity。java
最后,可能是支持库版本有问题。 尝试其他版本并清理项目