Что я сделал, чтобы создать fragment_graph.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="250dip"
android:id="@+id/graph1"
android:background="#102f65" />
</LinearLayout>
и добавить соответствующий код в классе Фрагмент:
public class GraphFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_graph, container, false);
// add the data here if necessary
// ...
LinearLayout layout = (LinearLayout) view.findViewById(R.id.graph1);
layout.addView(graphView);
return view;
}
// ...
}
Затем вы можете использовать фрагмент «как есть».
Большинство кредитов на самом деле относится к vogella.
Хорошо, спасибо! И вместо «этого» для контекста я просто должен использовать getActivity() – bastifix