Can you give layout_weight to the text view with code?

Asked 2 years ago, Updated 2 years ago, 63 views

I want to dynamically create TableRow in TableLayout. There are two items in Table Row: TextView and CheckBox. I'm going to give a weight of 1 for the text view I don't know how to search the document.

android layout textview android-layout-weight

2022-09-21 16:21

1 Answers

TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

You can do it like this. 1f of the last parameter is the value of weight.


2022-09-21 16:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.