我想将 3 个 HorizontalScrollView 添加到一个片段中。我已经成功实现了一个,但是当我尝试将另一个实现horizontalscrollview
到相同的片段中时,我得到了一个 HorizontalScrollView
只支持一个孩子的错误。所以,我horizontalscrollview
在 XML 中创建了另一个。我创建了第二个线性布局并将新的图像查看器 ID 传递给第二个线性布局,但它不会显示在屏幕上。
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" >
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="800px"
android:id="@+id/horizontalScroll"
android:background="#C6D7D2" android:layout_height="600px">
<LinearLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="800px"
android:id="@+id/horizontalScroll2"
android:background="#C6D7D2"
android:layout_height="600px">
<LinearLayout
android:id="@+id/container2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
这是java片段代码
public class FevFragment extends SherlockFragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.cfragment, container, false);
}
@Override
public void onStart() {
super.onStart();
/** Setting the multiselect choice mode for the listview */
initfrag();
}
private void initfrag() {
LinearLayout linearlayout1 = (LinearLayout)getView().findViewById(R.id.container);
LinearLayout linearlayout2 = (LinearLayout)getView().findViewById(R.id.container2);
for (int i = 0; i < 15; i++) {
ImageView iv = new ImageView(getActivity());
iv.setPadding(5, 55, 5, 5);
iv.setImageResource(R.drawable.test_play_image);
linearlayout1.addView(iv, 260, 260);
ImageView iv2 = new ImageView(getActivity());
iv2.setPadding(5, 255, 5, 5);
iv2.setImageResource(R.drawable.test_play_image);
linearlayout2.addView(iv2, 100, 100);
TextView tv = new TextView(getActivity());
tv.setText("testing");
tv.setPadding(5, 55, 5, 5);
linearlayout1.addView(tv, 100, 100);
}
} }