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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:02:22+00:00 2026-05-26T13:02:22+00:00

I have 5 square ImageButtons that I want to have lined up side by

  • 0

I have 5 square ImageButtons that I want to have lined up side by side on the bottom of the screen. I have each one set (different id’s) as:

        <ImageButton
         android:id="@+id/box1" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:layout_gravity="center"
         android:adjustViewBounds="true"
         android:scaleType="fitXY"
         android:layout_weight="1"
         android:layout_margin="1dp"
         /> 

and I have the background assigned in main java like this:

    int[] imageIds = new int[] {R.id.box1,R.id.box2,R.id.box3,R.id.box4,R.id.box5};
    for(int i = 0; i<5; i++){
        imageButtons[i] = (ImageButton) findViewById(imageIds[i]);
        imageButtons[i].setBackgroundResource(R.drawable.blank);
    }

What I would like to have it do is scale the width to fit neatly side-by-side at the bottom of the screen (which it does now ok), but have the height automatically scale to match the width as well. is this possible? I don’t want to use setImageSource because then it puts a border around the imagebutton.

  • 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-26T13:02:22+00:00Added an answer on May 26, 2026 at 1:02 pm
       <LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:id="@+id/layoutButtons">
    
         <com.package.SquareButton         
            android:layout_height="fill_parent"
            android:layout_width="0dip"          
            android:layout_weight="1"
    
            <ImageView
            android:id="@+id/box1"
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:layout_height="wrap_content"
            android:layout_width="0dp"          
            android:layout_weight="1" 
            android:layout_marginLeft="5dp" 
            android:layout_marginRight="5dp"/>
    
          </com.package.SquareButton>
    
          <com.package.SquareButton         
            android:layout_height="fill_parent"
            android:layout_width="0dip"          
            android:layout_weight="1"
    
            <ImageView
            android:id="@+id/box2"
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"          
            android:layout_marginLeft="5dp" 
            android:layout_marginRight="5dp"/>
    
    </com.package.SquareButton>
    
       .........          
     </LinearLayout>
    

    And then add this custom button class:

    public class SquareButton extends LinearLayout {
    
        public SquareButton(Context context) {
            super(context);
        }
    
        public SquareButton(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        // This is used to make square buttons.
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, widthMeasureSpec);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many square images with different sizes, and I want to first resize
I have a square DIV(300px x 300px) that I want to flip every 5
I have a square that has dimensions 10x10 and I want to divide it
I have 3 square. smallest square s3 is inside s2. s2 is in side
I have this code and I want to have my button as a square,
I have created/tried to create, a round button for android by using the ImageButton
So I have a square that's made up of a series of points. At
I have a square matrix file, and I want to load it into Perl.
I want to have something like this five buttons, one button surrounded by four
I have a square movieclip on stage. I am trying to set the dimensions

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.