@asdf999
Android Programmer

Почему TableLayout расширяется по высоте, если добавлять TableRow программно?

Есть 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));
    }


03711313f2da4272be1be24a0e677737.png
  • Вопрос задан
  • 3062 просмотра
Пригласить эксперта
Ответы на вопрос 1
@StanKo
По-моему все так и должно быть содержимое врапается нормально в скроллл, ведь тот весь экран занимает, иначе надо ограничить высоту TableView до 1 строки, либо ScrollView. Либо юзать ListView.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы