I’m finding it very complicated to fix the layout in xml

Asked

Viewed 40 times

-1

I want to make a simple menu. But it gets all crooked Why do I do? Someone gives me tips? I’m new to android.

<?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:background="#FFFFFF"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="projeto.ba.gr.noamobile.MenuActivity"
tools:showIn="@layout/app_bar_menu"
android:orientation="vertical">


<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="50dp"
    android:layout_weight="50">

    <Button
        android:id="@+id/btnAlerta"
        android:layout_marginTop="50dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF"
        android:layout_marginLeft="80dp" />

    <Button
        android:layout_marginRight="50dp"
        android:id="@+id/btnNoaCidadao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF"
        android:layout_marginTop="50dp"
        />

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_weight="50"
    android:layout_gravity="center_horizontal"
    >

    <Button
        android:id="@+id/btnOperacao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF"
        android:layout_marginLeft="80dp"/>
    <Button
        android:id="@+id/btnMul"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF"/>
</LinearLayout>
</LinearLayout>
  • 5

    Add a photo of what you’re trying to build, or a better description, "a menu" is very broad. It would be nice a photo of how your project is currently, to understand what is "crooked"

  • Suddenly Linearlayout is not what you need, try others like Relative or Frame

1 answer

1

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="50dp"
    android:layout_weight="1">

    <Button
        android:id="@+id/btnAlerta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:layout_weight="1"
        android:background="#FFFFFF" />

    <Button
        android:id="@+id/btnNoaCidadao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:layout_weight="1"
        android:background="#FFFFFF" />

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_gravity="center_horizontal"
    >

    <Button
        android:id="@+id/btnOperacao"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:layout_weight="1"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF" />
    <Button
        android:id="@+id/btnMul"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TESTE"
        android:layout_weight="1"
        android:drawableTop="@drawable/aviso"
        android:background="#FFFFFF"/>
</LinearLayout>

I set up your layout. the "weight" (Weight) this comes 50, I changed the two to 1, so it gets 50% simpler.

There were layout_margins values too.

I believe that it solves.

Browser other questions tagged

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