3

I have two types of content for TableRow. One has two lines and the other one. I wish everyone had the same height. I'm trying something like this:

tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, 80));

Any other ideas? And, how can I transform "80" in dp?

coffee
  • 3,048
  • 4
  • 32
  • 46
  • 1
    [Here's another SO question about setting values in DP programatically](http://stackoverflow.com/questions/5255184/android-and-setting-width-and-height-programmatically-in-dp-units) – Doug Stephen Jun 20 '11 at 16:01
  • 3
    Does this answer your question? [Android and setting width and height programmatically in dp units](https://stackoverflow.com/questions/5255184/android-and-setting-width-and-height-programmatically-in-dp-units) – Saeed All Gharaee Feb 15 '21 at 13:24
  • This post solved my problem https://stackoverflow.com/questions/5255184/android-and-setting-width-and-height-programmatically-in-dp-units – coffee Jun 25 '11 at 19:50

3 Answers3

1

you can set the hight by setting the padding

    <TableRow

        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        >

for dynamic

tr.setPadding(0, 12, 0, 12);

Issac Balaji
  • 1,441
  • 1
  • 13
  • 25
0

You could use two different layouts for the rows and just assign them dynamically in your code. Define the heights in your layouts.

SBerg413
  • 14,515
  • 6
  • 62
  • 88
  • I wanna do that programmatically – coffee Jun 20 '11 at 16:56
  • OK then. The 2nd parameter is the height. So what you need to do is make that wrap_content. Like this: TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT) – SBerg413 Jun 22 '11 at 12:39
  • Sorry if I wasnt clear... but I dont wanna Wrap.. I wish define a number to my height, like I said on my ask. – coffee Jun 23 '11 at 15:29
-1

I Solve this with getViewTreeObserver. You must type this method on the tableLayout AND override onGlobalLayout.

Inside this method, you can verify all child's height. Then you can identify Max heigh.

4b0
  • 21,981
  • 30
  • 95
  • 142