私は GridLayout (GridView ではありません!) を使用して、次のようなレイアウトを実現しようとしています:
しかし、私のコード (およびこれまでに試したすべてのこと) では、水平方向に隣接する 2 つのビューの上部が常に整列されます。代わりに、新しい各ビューをその列の最高水準点に合わせて配置するように指示することはできますか? ( 「自動インデックス割り当て」の下の新しいレイアウト ウィジェット: Space および 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);
}