"stretch" line on tablelayout

Asked

Viewed 357 times

0

Well, I’m coding android, and building layouts for my app. My problem: I can’t make my app layout fit vertically to different devices.

my xml code:

```

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="50dp" >

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />
</TableRow>

<TableRow
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ToggleButton
        android:id="@+id/toggleButton6"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton7"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton8"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton9"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton10"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />
</TableRow>

<TableRow
    android:id="@+id/tableRow4"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ToggleButton
        android:id="@+id/toggleButton11"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton12"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton13"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton14"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />

    <ToggleButton
        android:id="@+id/toggleButton15"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ToggleButton" />
</TableRow>

<TableRow
    android:id="@+id/tableRow5"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Button" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="TextView" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</TableRow>

```

I wish my buttons longed for size alone when the screen increases, horizontally it already happens due to the tablelayout stretchColumns but how do I make it occur in the vertical tbm?

thank you!

  • Joannis, take a look at my answer to that question: http://answall.com/questions/33393/como-cria-bot%C3%B5es-with-size-din%C3%A2mico-em-xml/33416#33416. On it the buttons resize according to screen size and orientation.

1 answer

2


Good, see that you are using Tablerow.

Tablerow’s father must be Tablelayout, by the Google Guilds.

Your Tablelayout, with multiple Tablerows inside, should be with Fill or match Parent in both height and width.

If you want to set fixed value to height, as I saw in your example, of 50dp, you can set a dimen.

Create a Dimen file in the values folder with:

50 dp

This will be the default attribute.

For other resolutions, dimensions, densities, etc...

You can create another values folder, such as values-small

And put this same dimen with lower value, for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.