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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:14:36+00:00 2026-06-05T15:14:36+00:00

I have a radiogroup in xml, and the buttons are generated programmatically. How do

  • 0

I have a radiogroup in xml, and the buttons are generated programmatically. How do I add spacing between the buttons programmatically.

I thought it was something like LayoutParams but my object doesn’t come with an obvious setPadding or setMargins method.

This is what I was trying

RadioButton currentButton = new RadioButton(context);
            currentButton.setText(item.getLabel());
            currentButton.setTextColor(Color.BLACK);

            //add padding between buttons
            LayoutParams params = new LayoutParams(context, null);
            params. ... ??????
            currentButton.setLayoutParams(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-06-05T15:14:37+00:00Added an answer on June 5, 2026 at 3:14 pm

    Padding

    Normal LayoutParams don’t have methods to apply padding, but views do. Since a RadioButton is a subclass of view, you can use View.setPadding(), for example like this:

    currentButton.setPadding(0, 10, 0, 10);
    

    This adds 10px padding at the top and 10px at the bottom. If you want to use other units beside px (e.g. dp) you can use TypedValue.applyDimension() to convert them to pixels first.

    Margins

    Margins are applied to some specific LayoutParams classes which subclass MarginLayoutParams. Make sure to use a specific subclass when setting a margin, e.g. RadioGroup.LayoutParams instead of the generic ViewGroup.LayoutParams (when your parent layout is a RadioGroup). Then you can simply use MarginLayoutParams.setMargins().

    Sample:

    RadioGroup.LayoutParams params 
               = new RadioGroup.LayoutParams(context, null);
    params.setMargins(10, 0, 10, 0);
    currentButton.setLayoutParams(params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sucessfully made and used RadioGroup's before in xml, but each time there
I would like to have radio buttons in one radiogroup divided into 2 columns
I have a RadioGroup with four check buttons. I'd like to create a slide
I have a radio button group like this : <g:radioGroup name=myGroup values=[1,2,3] value=1 >
I have a RadioGroup with four radio buttons, I have them using weightsum of
I'm trying to set a margin to RadioButtons added programmatically to a RadioGroup, but
I have a radiogroup with custom radiobuttons. Icons are set using rbFirst.setButtonDrawable(R.drawable.first); But icon
If I have a page whose layout is designated by XML code, but I
I have Radio buttons that are created dynamically. LinearLayout linLayRoot = (LinearLayout)dialogView.findViewById(R.id.dialog_layout_root); RadioGroup radGp
So I declare an ExtJS radio button object like this: .AddExtObject({xtype:'radiogroup', ref:'../AndOr', defaults:{name:'rdo-payee2'}, width:120,

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.