Android不会动态地向滚动视图添加视图

时间:2013-10-19 12:19:46

标签: android scrollview

尝试在循环中动态地向scrollview添加一些视图,但是在滚动视图中没有任何效果或任何类型的崩溃,并且在循环中添加表行视图

///循环运行5次

ScrollView parent = (ScrollView) root.getRootView()
                                .findViewById(R.id.scrolltbl);
                            View child = getLayoutInflater(
                                    savedInstanceState).inflate(R.layout.attditem, null);

                            String lecs = findint(tds.text());// attdTile
                            String leves = findint(leaves.text());
                            String abs = findint(absents.text());

                        ((TextView)child.findViewById(R.id.lecs))
                                    .setText(lecs);
                            ((TextView)child.findViewById(R.id.lvs))
                                    .setText(leves);
                            ((TextView)child.findViewById(R.id.abs))
                                    .setText(abs);
                            ((TextView)child.findViewById(R.id.crsname))
                            .setText(tTrs[f]);
                            Log.w("count","2d");
                            parent.addView(child);

1 个答案:

答案 0 :(得分:1)

您无法在scrollview中添加多个视图。在scrollView和此视图中的内容中使用LinearLayout。最后在ScrollView中添加linearlayout