首先,在Fragment (本例中叫fragment2) 中以xml配置一個LinearLayout,在本例子中id設為f2_layout
覆蓋onCreateView
v = inflater.inflate(R.layout.frament2, container, false);
View pl = v.findViewById(R.id.f2_layout);
ScrollView scroller = new ScrollView(pl.getContext());
TextView t = new TextView(pl.getContext());
scroller.addView(t);
t.setText("test");
((LinearLayout)pl).addView(scroller);
}
請先 登入 以發表留言。