我试图使用网格布局随时添加新的意见,以实现这样的布局(不GridView的!):Android的网格布局:在高水位标记
但是我的代码(和一切我尝试了直到现在)两个水平相邻视图的顶部始终对齐。是否有可能将每个新视图与其列的高水位标记对齐? (见New Layout Widgets: Space and GridLayout下的 “自动索引分配”)
我layout.xml貌似现在这种权利:
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:columnCount="2"
/>
为了这个网格布局添加我的意见编程:
GridLayout scrollViewContainer = Views.findById(rootView, R.id.scroll_view_container);
for (i=0; i < list.size(); i++)
TextView tv = new TextView(context);
tv.setText("foobar");
GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
// left, right, left, right - creates new default rows
lp.columnSpec = GridLayout.spec(i%2);
// this would put every view in the same row => all Views are on the very top
// lp.rowSpec = GridLayout.spec(0);
tv.setLayoutParams(lp);
scrollViewContainer.addView(tv);
}