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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:24:22+00:00 2026-06-14T16:24:22+00:00

What I am trying to do is simply add an imageButton view as a

  • 0

What I am trying to do is simply add an imageButton view as a child of a custom view, in the top right corner. My custom view extends Webview. I have had no problem adding the imageButton to my custom view, I just can’t move it to the top right corner. I need to do this programmatically, not in xml. I would never think something this simple would require me to post on here, but I really can’t figure it out.

Here is what I am using to add the imageButton to the custom view currently, but it’s at the top left corner:

    public class customView extends WebView {

      private void imageButtonInit() {
         ImageButton closeImageButton = new ImageButton(getContext());
         Drawable image = getResources().getDrawable(com.package.image);
         closeImageButton.setBackgroundDrawable(image);
         closeImageButton.setLayoutParams(new RelativeLayout.LayoutParams(25, 25));
         closeImageButton.bringToFront();
         customView.this.addView(closeImageButton);
      }
    }

What I have tried in order to move it to the top right corner:

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(25, 25);
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, -1);
    closeImageButton.setLayoutParams(lp);
    customView.this.addView(closeImageButton);

As well as:

    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(25, 25, Gravity.RIGHT|Gravity.TOP);
    closeImageButton.setLayoutParams(lp);
    customView.this.addView(closeImageButton);

All of which results in the imageButton being placed in the top left corner. This is my first post on this site so I hope the question is properly formatted. Please no xml solutions. Thanks everyone.

  • 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-06-14T16:24:23+00:00Added an answer on June 14, 2026 at 4:24 pm

    I think what you are doing in your other two methods is literally setting your CustomView to have those layout params. What you should try instead is set the layout params of your child using this method;

        customView.this.addView(child, params);
    

    where child is your image button and params is the layout params.

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

Sidebar

Related Questions

Im currently trying to simply add a block to a custom Adminhtml module. i
I am trying to simply add a Google Search bar onto my own map
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
I'm trying to simply add +1 to an array like this $game['teamA']['goals']++; But then
I'm simply trying to add a UIView for every object in an array without
I am simply trying to add a separator line under my header row in
i'm trying to write a very simple wysiwyg editor, where users can simply add
I'm simply trying to add a file to my Xcode resources folder and it
I'm trying to extend the DropDownList control to simply add one extra property. Code
I'm simply trying to add a bulleted list in an ASP.NET aspx page. I

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.