============问题描述============
图片如上,为什么fragment不占满整个content啊?
代码如下:
Action.java:
ft.replace(R.id.content, new NoteFragment());
fragment.java:
public class AllQuestionFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.allquestion_ui,null);
return view;
allquestion_ui.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="A"
android:gravity="center"
android:id="@+id/tv_fragment"
/>
</LinearLayout>
============解决方案1============
android:layout_weight="1"这行去掉
============解决方案2============
你activity的布局文件有问题
============解决方案3============
fragment是要放在你activity里的,在activity里有对fragment属性的设置,或者是fragment replace了activity里的某个view,因该查一下activity里的布局是不是match_parent