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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:24:48+00:00 2026-05-16T18:24:48+00:00

I see posts saying that FrameLayout is the alternative, and that I should use

  • 0

I see posts saying that FrameLayout is the alternative, and that I should use margins to position things (this strikes me as wildly counter intuitive, but ok… if it works, I’ll take it). However, I can’t get it to work, so, I’m looking for assistance.

here’s my code

    FrameLayout layout = new FrameLayout(this);
    layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    Button btn = new Button(this);
    btn.setBackgroundResource(R.drawable.btn);

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.setMargins(100,100,100,100);

    btn.setLayoutParams(lp);   //i've tried with and without this line, no change

    layout.addView(btn , lp);

The button is drawn at 0,0 no matter what I do. When I change the lp’s LayoutParam to FILL_PARENT the button is then stretched to take up the entire screen (which makes sense).

HOW do you get it to draw somewhere else on the screen, irrespective of what else is there?

As always, super grateful in advance.

[EDIT]
It seems my question isn’t entirely clear (given the answers) so…

In the code above, the intent is to create a button, pass it to a layout and have it draw at 100,100 on the screen.

I’m aware of the fact that this may mean different things on different devices. I’m ok with that. I simply need a way to, programatically, and at run time, place an item at a SPECIFIC location. I don’t want to rely on gravity (or the laws of thermodynamics). I just want to specify a location and have the element appear there 🙂

  • 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-16T18:24:49+00:00Added an answer on May 16, 2026 at 6:24 pm

    As many have pointed out, setting a button at an absolute pixel position on the screen is a really bad idea, and will never work across all of the available android phones. I’m sure there is a better way to achieve the layout you want.

    However, to answer the question as asked: to position it at runtime you can use the AbsoluteLayout.LayoutParms.

    AbsoluteLayout absoluteLayout = //get absolute layout
    
    Button button = new Button();
    AbsoluteLayout.LayoutParms params = absoluteLayout.generateDefaultLayoutParams();
    params.x = 100;
    params.y = 100;
    
    absoluteLayout.addView(button, params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read that great post on Visual Studio 2008 annoyances, but didn't see this
Every time I try to run my script I get this error, saying that
I see a number of posts talk about rolling your own LINQ to SQL
I see a lot of people in blog posts and here on SO either
By @user.posts , I can see there is a post with :unfinished status. But
I screwed up my last post. Lets see if I can get this one
I know there has been a lot of posts on this but it still
I tried to use a Facebook comment plugin so that I can moderate comments
I'll start off by saying I'm a noob with all of this, I have
I am trying to build a script that posts information into the RoyalMail tracking

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.