Java I';我没有在fragment类中获得我的片段布局引用(顶部部分片段)
这是我的片段布局顶部部分Java I';我没有在fragment类中获得我的片段布局引用(顶部部分片段),java,android,android-fragments,Java,Android,Android Fragments,这是我的片段布局顶部部分 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >`enter code here`
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>`enter code here`
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:layout_centerHorizontal="true"
android:width="250dp"
android:height="50dp"
android:layout_marginTop="100dp"></EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="299dp"
android:text="Click Here"></Button>
</RelativeLayout>
我没有使用R.layout在fragment类中获取片段布局。请按如下方式操作:
View view = inflater.inflate(R.layout.top_section_fragment, container, false);
return view;
你得到了什么?在文件菜单下找不到symbol top\u section\u fragmentTry Invalidate Caches/Restart。我想这可能是因为
inflate()
并没有像setContentView()
那样只接受一个参数。看起来你忘记导入R
类了。另外,SkypeDogg关于膨胀(…)的观点也站得住脚。
View view = inflater.inflate(R.layout.top_section_fragment, container, false);
return view;