我有 DetailsFragment 类,这个类向“fragment”xml 添加两个按钮,但是当我向“scroller”添加两个按钮时,程序显示“ScrollView 只能承载一个直接子项”。请帮我在java代码中添加两个按钮到“scroller”。
public class DetailsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.t);
ScrollView scroller = new ScrollView(getActivity());
Button m =new Button(getActivity());
m.setText("adfgadgfdsfg");
m.setWidth(100);
m.setHeight(30);
m.setTextSize(30);
scroller.addView(m);
//*** expiation in this code but when i clear m1 code is work
Button m1 =new Button(getActivity());
m1.setText("adfgadgfdsfg");
m1.setWidth(100);
m1.setHeight(30);
m1.setTextSize(30);
scroller.addView(m1);
}
}
代码xml布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ti"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment
android:id="@+id/titles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_detial_fragment"
/>
<LinearLayout
android:id="@+id/t"
android:layout_width="match_parent"
android:layout_height="match_parent"
></LinearLayout>
</FrameLayout>