2013-05-14 69 views
0

我想在片段中添加自己的圖形。 是否可以在片段中添加例如一個圓圈? 我有這樣的代碼:在片段中繪製

public static class DummySectionFragment extends Fragment { 
    /** 
    * The fragment argument representing the section number for this 
    * fragment. 
    */ 
    public static final String ARG_SECTION_NUMBER = "section_number"; 
    public static final String ARG_OBJECT = "object"; 
    public static final String ARG_DATA = "data"; 


    public DummySectionFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     Bundle args = getArguments(); 
     int position = args.getInt(ARG_OBJECT); 
     String data=args.getString(ARG_DATA); 
     int tabLayout = 0; 
     switch (position) { 
     case 0: 
     tabLayout = R.layout.fragment_company_products; 
     break; 
     case 1: 
     tabLayout = R.layout.fragment_main_dummy; 
     break; 
     case 2: 
     tabLayout = R.layout.fragment_main_dummy; 
     break; 
     case 3: 
      tabLayout = R.layout.fragment_main_dummy; 
     break; 
     } 

     View rootView = inflater.inflate(tabLayout, container, false); 

     TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label); 

     //dummyTextView.setText(args.getInt(ARG_OBJECT)+"\n"+data+"asd"); 
     return rootView; 
    } 


} 

我問這個,因爲我想改變每個片段我的圖形,以及一些那些片段的我要補充一些2D圖形像圓或圓弧或長方形。 這可能嗎? 預先感謝您

回答

-1

有可能View子類添加到您的Fragment的佈局並進行自定義在onDraw繪圖。

+0

哦,很高興謝謝:) – Francesco

+0

你知道我該如何選擇自定義視圖嗎? – Francesco

+0

碎片膨脹正常佈局。只需將您的自定義視圖放置在片段膨脹的佈局中即可 –