Есть TableLayout внутри SrcollView. Высота как видите wrap_content.
Добавляю динамически TableRow-s и TableLayout расширяется по высоте. То есть добавлено всего две строки, а занято куча свободного пространства.
Оранжевым окрашены TableRow, красным TableLayout.
Как сделать высоту TableLayout равным сумме высот TableRow?
<ScrollView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/ordersTableLayout"
android:background="@color/red"
>
</TableLayout>
</LinearLayout>
</ScrollView>
final TableLayout tableLayout = (TableLayout) getView().findViewById(R.id.ordersTableLayout);
tableLayout.removeAllViews();
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < basketData.getGoodItems().size(); i++) {
final View view = inflater.inflate(R.layout.order_item2, null);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(layoutParams);
BasketData.GoodItem goodItem = basketData.getGoodItems().get(i);
float price = Float.parseFloat(goodItem.getItem().getPrice());
TextView orderNameTextView = (TextView) view.findViewById(R.id.orderNameTextView);
TextView orderCountTextView = (TextView) view.findViewById(R.id.orderCountTextView);
TextView orderPriceTextView = (TextView) view.findViewById(R.id.orderPriceTextView);
orderNameTextView.setText( Html.fromHtml(goodItem.getItem().getName()) );
orderPriceTextView.setText(goodItem.getCount() * price + "p");
orderCountTextView.setText(goodItem.getCount() + "");
tableLayout.addView(view, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
}