Ask Your Question
1

How can I place a button over other buttons in a linear layout?

asked 2023-06-30 13:57:22 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-30 14:03:01 +0000

plato gravatar image

You can use the android:layout_gravity attribute and set it to center for the button that you want to place over other buttons. Here is an example code snippet:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2"
        android:layout_gravity="center"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 3"/>

</LinearLayout>

In the above code, the android:layout_gravity attribute is set to center for the second button, which will place it in the center of the linear layout and on top of the other buttons.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-30 13:57:22 +0000

Seen: 9 times

Last updated: Jun 30 '23