1

¿Cómo puedo hacer que los botones inferiores se alineen de izquierda a derecha en vez de arriba a abajo y que ocupen todo el ancho del dispositivo que lo ejecute? ¿Puedo emplear porcentajes?

Situación actual

Adjunto código:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/background">

<LinearLayout
    android:id="@+id/saldoLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/saldoTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/saldo"
        android:textColor="@color/letra"
        android:textSize="24sp"
        android:textAlignment="center"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/topLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="125dp"
    android:layout_below="@+id/saldoLinearLayout"
    android:orientation="horizontal">

</LinearLayout>

<LinearLayout
    android:id="@+id/midTableLayout"
    android:layout_width="match_parent"
    android:layout_height="355dp"
    android:layout_below="@+id/topLinearLayout"
    android:orientation="vertical">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/topLinearLayout"
        android:layout_centerHorizontal="true"
        android:text="Button" />

    <Button
        android:id="@+id/button10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button"
        android:layout_below="@+id/button"
        android:text="Button" />

    <Button
        android:id="@+id/button13"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button4"
        android:layout_below="@+id/button4"
        android:text="Button" />

    <Button
        android:id="@+id/button11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button12"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button2"
        android:layout_below="@+id/button2"
        android:text="Button" />

    <Button
        android:id="@+id/button6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button5"
        android:layout_below="@+id/button5"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button3"
        android:layout_below="@+id/button3"
        android:text="Button" />

    <Button
        android:id="@+id/button8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:id="@+id/menuLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/midTableLayout"
    android:orientation="vertical">

    <Button
        android:id="@+id/homeButton"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Home" />

    <Button
        android:id="@+id/noticiasButton"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Noticias" />

    <Button
        android:id="@+id/estadoButton"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Estado" />
</LinearLayout>

</RelativeLayout>

2 respuestas 2

0

Intenta esto(solo es el código relevante para los botones):

<LinearLayout 
    android:id="@+id/menuLinearLayout"
    android:layout_below="@+id/midTableLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

   <Button
        android:id="@+id/homeButton"
        android:text="Botón 1"
        android:layout_weight="1"/>

   <Button
        android:id="@+id/noticiasButton"
        android:text="Botón 2"
        android:layout_weight="1"/>

   <Button
        android:id="@+id/estadoButton"
        android:text="Botón 3"
        android:layout_weight="1"/>

</LinearLayout>
2
  • diste con la solucion gracias ;D el 21 abr. 2017 a las 19:30
  • !Excelente!... :)
    – Rene Limon
    el 21 abr. 2017 a las 19:32
0

Es por que esos 3 Botones tienen una medida fija que en tu caso es de 100dp :

androidlayout_width="100dp"

Para que ocuparan todo el ancho solo debes dejarlo igual a como los tienes arriba :

android:layout_width="match_parent"
3
  • si pero de esa manera me ocupa un boton todo el ancho. Lo que yo trarto es que en una unica fila tenga los tres botones. el 21 abr. 2017 a las 17:23
  • Y ya intentaste poner android:layout_width="wrap_content" ? el 21 abr. 2017 a las 17:31
  • bien cambie ese atributo y la orientacion del linear layout lo unico que ahora quiero que abarque todo el ancho del layout y se ajusta a la izquierda como podria hacer que se quede de esta manera : articles-images.sftcdn.net/wp-content/uploads/sites/2/2013/08/… el 21 abr. 2017 a las 17:37

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.