【发布时间】:2015-07-03 18:43:16
【问题描述】:
我正在尝试使用 GridLayout(不是 GridView!)来实现这样的布局:
但是对于我的代码(以及到目前为止我尝试过的所有内容),两个水平相邻视图的顶部总是对齐的。是否可以告诉每个新视图与其列的高水位线对齐? (参见“自动索引分配”下的New Layout Widgets: Space and GridLayout)
我的 layout.xml 现在看起来像这样:
<GridLayout
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 添加我的视图:
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);
}
【问题讨论】:
标签: android android-layout android-gridlayout