How to fix the size of a button on android?

Asked

Viewed 1,020 times

2

Could someone give me a tip on how to avoid the problem below?

I have these buttons and I would like to leave them in a fixed size, so they do not ditor when the phone is rotated.

Tamanho Correto

Imagem errada.

I am using Relativelayout:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >

Button settings:

<Button
    android:text="Onde ir?"
    android:layout_width="wrap_content"
    android:id="@+id/button9"
    android:background="@drawable/mapabutton"
    android:textColor="@color/TextoBotao"
    android:textSize="20sp"
    android:layout_height="60dp"
    android:layout_weight="0.5"
    android:fontFamily="sans-serif-condensed"
    tools:fontFamily="serif"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

1 answer

4


Only modify "wrap_content" to the desired size or remove layout_weight

<Button
    android:text="Onde ir?"
    // altere para o tamanho que você quizer
    android:layout_width="300dp"
    android:id="@+id/button9"
    android:background="@drawable/mapabutton"
    android:textColor="@color/TextoBotao"
    android:textSize="20sp"
    android:layout_height="60dp"
    android:layout_weight="0.5" //comentar essa linha também deve resolver
    android:fontFamily="sans-serif-condensed"
    tools:fontFamily="serif"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

Browser other questions tagged

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