2017-08-26 154 views
1

,当我从activity数据传递到fragment我得到这个:问题与片段布局

https://i.stack.imgur.com/L0Si4.png

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

这是代码当我传递数据:

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; 
    } 

FRAGMENT_LIST_2_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> 

如果我把

的android:背景= “@色/白” 到:

<?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> 

我得到这个:

enter image description here

+0

请分享您的片段XML代码@androidiano –

+0

发表您的项目XML代码 –

+0

我加入它!!!!! – androidiano

回答

0

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

<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> 

我可以在此图像中看到它不重叠的权利。

enter image description here

+0

我必须把这个? – androidiano

+0

将其添加到片段xml中的父布局 –

+0

请参阅我的代码更新请 – androidiano