Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 577135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:07:16+00:00 2026-05-13T14:07:16+00:00

I have a simple demo with two buttons. They are laid out with a

  • 0

I have a simple demo with two buttons. They are laid out with a RelativeLayout at the top and bottom of the screen.
When I click one of them, I want them to switch places.
What is the best way to do that?

This is my res/layout/main.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageButton
        android:id="@+id/android_button_1"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:src="@drawable/icon"
        android:layout_alignParentTop="true" />

    <ImageButton
        android:id="@+id/android_button_2"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:src="@drawable/icon2"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

And this is my Activity:

public class HelloButtons extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        final ImageButton button1 = (ImageButton) findViewById(R.id.android_button_1);
        final ImageButton button2 = (ImageButton) findViewById(R.id.android_button_2);
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloButtons.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        button2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloButtons.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:07:16+00:00Added an answer on May 13, 2026 at 2:07 pm

    Use something along these lines

       RelativeLayout.LayoutParams lp1 = (LayoutParams) b1.getLayoutParams();
       RelativeLayout.LayoutParams lp2 = (LayoutParams) b2.getLayoutParams();
    
       lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
       lp2.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
       lp1.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
       lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    
       b1.setLayoutParams(lp1);
       b2.setLayoutParams(lp2);
    

    (and the opposite to revert them again) in you OnClickListeners

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple database - one table with 6 collumns. 3 of them i
I am using EF (Framework 3.5 SP1) and have a simple two table demo
I am about to create a simple demo in flash where I have 3
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have a very simple demo working that uses Webkit transforms and transitions for
I am experimeting with web sockets. I look at http://www.websocket.org/echo.html site... They have simple
Fiddle demo available here: http://jsfiddle.net/r9MCW/5/ The functionality Basically, I have a very simple table
I have this simple HTML structure: <ul> <li> One <p> Foo is a fool.
I have a demo here to illustrate my problem http://www.ttmt.org.uk/ It's just a simple
I have a fairly simple layout with two rows. The second row has two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.