Buttons of a Linearlayout are getting giant

Asked

Viewed 27 times

1

I want to adjust the buttons so that they are underneath each other, but when I try to put, they are wide and not like a normal button. See:

inserir a descrição da imagem aqui

The xml is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:onClick="Propaganda"
        android:text="@string/propaganda" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:onClick="BotaoNavegacao"
        android:text="@string/navega_o" />


    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:onClick="LoginActivity"
        android:text="@string/login" />

</LinearLayout>

How can I adjust them?

  • They are one below the other in the photo you sent. How should they be?

  • You’re right Pablo. I expressed myself badly. I made an adjustment in my Post. In fact they get wide and not like a normal button.

1 answer

3


Your problem is you’re giving layout_weight 1 for all buttons. This makes them all try to occupy their father’s full space, and end up with a third each. As their father is occupying the entire screen, each gets a third of the screen.

Remove the lines android:layout_weight="1" or change the height of LinearLayout for wrap_content that your problem goes away.

  • Perfect Pablo. It worked with the two tips you went through. Thank you so much.

Browser other questions tagged

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