Android 画一个碎片
我想在片段中添加我自己的图形。 例如,是否可以在片段中添加一个圆? 我有以下代码:Android 画一个碎片,android,Android,我想在片段中添加我自己的图形。 例如,是否可以在片段中添加一个圆? 我有以下代码: public static class DummySectionFragment extends Fragment { /** * The fragment argument representing the section number for this * fragment. */ public static final String ARG_SECTION_N
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图形,如圆形、圆弧或矩形。
这可能吗?
提前感谢您您可以将
视图
子类添加到片段
的布局中,并在onDraw中进行自定义绘图。您知道如何选择该自定义视图吗?片段会使常规布局膨胀。只需将您的自定义视图放在碎片膨胀的布局中。。。