Java 碎片布局问题

Java 碎片布局问题,java,android,android-fragments,Java,Android,Android Fragments,当我将数据从活动传递到片段时,我得到以下结果: 为什么碎片重叠?我只需要选中复选框的片段 这是我传递数据时的代码: Bundle bundle = new Bundle(); bundle.putIntegerArrayList("oki", hm); bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze); System.out.println(

当我将数据从
活动
传递到
片段
时,我得到以下结果:

为什么碎片重叠?我只需要选中复选框的片段

这是我传递数据时的代码:

Bundle bundle = new Bundle();
            bundle.putIntegerArrayList("oki", hm);
            bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze);

            System.out.println("PERO:" + bundle);
 MyListFragment2 myFragment = MyListFragment2.newInstance(hm,hm_quantitàpizze);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(android.R.id.content, myFragment);
            transaction.commit();
MYLISTFRAGMENT2:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        System.out.println("BUNDLES1 prima:" + bundle);

        bundle=getArguments();

        System.out.println("BUNDLES1 dopo:" + bundle);



        if (bundle != null) {
            strtext2 = bundle.getIntegerArrayList("daje");
            System.out.println("BUNDLES1 prima:" + strtext2);

            quantitàpizze2 = bundle.getIntegerArrayList("daje2");
            System.out.println("BUNDLES1 prima:" + quantitàpizze2);

        }

}




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the custom_spinner_items for this fragment
        //super.onDestroy();


        SharedPreferences settings = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.clear();
        editor.commit();


        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_list_2_2, container, false);





        return rootView;


    }




    public static MyListFragment2 newInstance(ArrayList<Integer> hm, ArrayList<Integer> hm_quantitàpizze) {
        MyListFragment2 fragment = new MyListFragment2();
        Bundle args = new Bundle();
        args.putIntegerArrayList("daje", hm);
        args.putIntegerArrayList("daje2", hm_quantitàpizze);
        fragment.setArguments(args);
        return fragment;
    }
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
System.out.println(“BUNDLES1 prima:+bundle”);
bundle=getArguments();
System.out.println(“BUNDLES1 dopo:+bundle”);
if(bundle!=null){
strtext2=bundle.getIntegerArrayList(“daje”);
System.out.println(“bundles1prima:+strtext2”);
quantitápizze2=bundle.getIntegerArrayList(“daje2”);
System.out.println(“BUNDLES1 prima:+quantitápizze2”);
}
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片的自定义\u微调器\u项目充气
//super.ondestory();
SharedReferences设置=getContext().GetSharedReferences(“状态”,Context.MODE\u PRIVATE);
SharedReferences.Editor=settings.edit();
编辑器.clear();
commit();
ViewGroup rootView=(ViewGroup)充气器。充气(R.layout.fragment\u list\u 2\u 2,容器,false);
返回rootView;
}
公共静态MyListFragment2新实例(ArrayList hm,ArrayList hm_quantitápizze){
MyListFragment2片段=新的MyListFragment2();
Bundle args=新Bundle();
参数putIntegerArrayList(“daje”,hm);
参数putIntegerArrayList(“daje2”,hm_quantitápizze);
fragment.setArguments(args);
返回片段;
}
片段列表\u 2\u 2:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/acab"
    android:layout_marginLeft="5dp"


    >
    <!--android:background="@color/white"-->
    <ListView
        android:id="@+id/listvieww"
        android:layout_marginTop="120dp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    </ListView>




</FrameLayout>

LISTVIEW的项目:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/welcome"
                    android:textSize="20dp"
                    android:layout_marginLeft="5dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20dp"
                    android:layout_marginLeft="5dp"
                    android:id="@+id/numero_tavolo"
                    />

                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:textColor="@color/lbl_name"
                    android:textSize="24dp"
                    android:layout_marginLeft="5dp"
                    />
              <!--  <Button
                    android:id="@+id/btnLogout"
                    android:layout_width="122dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="40dip"
                    android:background="@color/btn_login"
                    android:text="@string/btn_logout"
                    android:textAllCaps="false"
                    android:textColor="@color/white"
                    android:textSize="15dp"
                    android:layout_marginLeft="5dp"
                    android:onClick="logoutUser"

                    />-->

            </LinearLayout>

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabss"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            android:background="@color/colorPrimaryDark" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpagerr"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >
     <!--   <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
       <FrameLayout
           android:id="@+id/pero"

        android:layout_width="match_parent"
            android:layout_height="match_parent" />
        </LinearLayout>-->

    </android.support.v4.view.ViewPager>


</android.support.design.widget.CoordinatorLayout>

您应该在片段背景中使用一些颜色

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/acab"
    android:layout_marginLeft="5dp"
    android:background="@color/white">

    <ListView
        android:id="@+id/listvieww"
        android:layout_marginTop="120dp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    </ListView>




</FrameLayout>

我可以在这张图片中看到它没有重叠


您应该在片段背景中使用一些颜色

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/acab"
    android:layout_marginLeft="5dp"
    android:background="@color/white">

    <ListView
        android:id="@+id/listvieww"
        android:layout_marginTop="120dp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    </ListView>




</FrameLayout>

我可以在这张图片中看到它没有重叠



请分享您的片段xml代码@AndroidianPost您的项目xml代码我添加了它!!!!!好了,现在你让我饿了。@mohammaddrezakhalifeh我现在添加了它请分享你的片段xml代码@androidianost你的项目xml代码我添加了它!!!!!好吧,现在你让我饿了。@mohammaddrezakhalifeh我现在把它添加到我必须放这个的地方??将它添加到片段xml中的父布局检查我的更新答案并尝试一下。希望它不会重复检查我的代码更新…我试着像你建议的那样,但我有sam eproblemcheck我的答案我必须把它放在哪里??将它添加到片段XML中的父布局检查我的更新答案并尝试。希望它不会重复检查我的代码更新…我试着像你建议我,但我有问题检查我的答案