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 7128193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:06:46+00:00 2026-05-28T11:06:46+00:00

I am new to android and I want to retrieve button information which is

  • 0

I am new to android and I want to retrieve button information which is in the XML file. (specifically margin_top and margin_left). After that, i want to dynamically give another margins to that specific button in cording. I can create new button with new margin but i cant retrieve current button margins..

Any help would be appreciated.

android.view.ViewGroup.LayoutParams lay = btn1.getLayoutParams();

this lay object hold all the information but i cant get margins from that.

i created my button using following code.

RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeTest);
        Button btn3 = new Button(TestActivity.this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        params.setMargins(200, 200, 200, 200);
        layout.addView(btn3, params);
  • 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-28T11:06:47+00:00Added an answer on May 28, 2026 at 11:06 am

    Hi FlaMM3R

    My layout looks like below and you have to use same idea according to your layout.

    XML file

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"            
            android:text="@string/hello"
            android:id="@+id/tv" />
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button android:id="@+id/btn"
                android:layout_width="100dip"
                android:layout_height="100dip"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="40dp"
                android:layout_marginTop="36dp"
                android:text="Button" />    
            <Button android:id="@+id/btn2"
                android:layout_width="100dip"
                android:layout_height="100dip"
                android:layout_marginLeft="148dp"
                android:layout_marginTop="62dp"
                android:text="Button"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"/>
        </RelativeLayout> 
    </LinearLayout>
    

    Java file

    public class HelloActivity extends Activity {
        TextView tv;
        Button btn;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            tv =(TextView)findViewById(R.id.tv);
            btn = (Button)findViewById(R.id.btn);        
            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) btn.getLayoutParams();       
            tv.setText("left : "+params.leftMargin+"\ntop : "+params.topMargin);
            params.setMargins(10, 50, 0, 0); // setting new margins for btn
        }
    }
    

    Use same idea in your code and let me know what happened. I hope it will be the answer you are looking.

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

Sidebar

Related Questions

I am new in Android. I want to retrieve all reminders which are added
I have developed an Android App that contains a list of information. I want
i am new to android, i want to store the time and retrieve the
I am new in android, and want to design the layout which run in
Being new to Android, I want to know how we can retrieve the image
Im new to android and I want to create kind of CRUD with SQLite.
I am new to android and i want to import some classes to my
I am a new android app developer and i want to use google map
I am new in android and i want to do parsing through api and
I am new android app developer i want make app for tablets and phone

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.