Answer the question
In order to leave comments, you need to log in
Why does TableLayout expand in height when adding a TableRow programmatically?
There is a TableLayout inside SrcollView. Height as you can see wrap_content.
I add TableRow-s dynamically and the TableLayout expands in height. That is, only two lines are added, and a lot of free space is occupied.
TableRow is colored orange, TableLayout is red.
How to make TableLayout height equal to sum of TableRow heights?
<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));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question