DetailsFragment クラスがあり、このクラスは「fragment」xml に 2 つのボタンを追加しますが、「scroller」に 2 つのボタンを追加すると、「ScrollView は直接の子を 1 つしかホストできません」と表示されます。Javaコードで「スクローラー」に2つのボタンを追加するのを手伝ってください。
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>