Android Layout xml “buttons stacking” (newbie )

297
May 29, 2017, at 04:15 AM

I just started with android development. I just need a screen with some buttons on it that can contact a webserver, to trigger an action there, but i have not even gotten that far.

When i add buttons to the layout, even if they are nicely sided by side, they end up ontop of each other, with the button created last ontop.

And furtermore i have changed the color, but it does not seem to be moved end up in the simulator.

This is a fresh design (2nd try) and i dont understand what is going on. I dont really know what files to include :)

I realize this is something simple, but im just overwhelmed

thank you Lasse

Phone and design view

Answer 1

You're probably using a FrameLayout, which just stacks things on top of each other and only supports gravity.

For your use case, you can use a LinearLayout, a RelativeLayout or a ConstraintLayout. Here's an example using LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="Select releases since last candy fix" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="96dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:text="Button 1" />
        <Button
            android:layout_width="96dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            android:text="Button 2" />
    </LinearLayout>
</LinearLayout>

Have a look at the different layouts to see which one better fits your needs, ConstraintLayout would allow you to flatten your layout, which is good for performance.

Rent Charter Buses Company
READ ALSO
RecyclerView does not exist

RecyclerView does not exist

I cannot use tag <RecyclerView/> in the layout fileWhat the heck? Is it some weird mistake in the latest library update?

355
Android ADB Oem Unlocking

Android ADB Oem Unlocking

So I have got my phone in the bootloader and I want to unlock it so I type "fastboot oem unlock " and i get this

483
how to implement a Singleton Player in a service

how to implement a Singleton Player in a service

I have a class with a SingletonPlayer but I don't know how to implement to a service for play background

329
Displaying Google Map within service using window manager system service

Displaying Google Map within service using window manager system service

In my app I need to be able to display google map as overlay up on other applications

289