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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:48:12+00:00 2026-06-09T11:48:12+00:00

I have HorizontalScrollView and the problem is that after I add views, I have

  • 0

I have HorizontalScrollView and the problem is that after I add views, I have blank spaces between these views.. Here is a pic:
enter image description here

Here is the code of the class:

public class HomeFeatureLayout extends HorizontalScrollView {
    public HomeFeatureLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public HomeFeatureLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HomeFeatureLayout(Context context) {
        super(context);
    }

    public void setFeatureItems() {
        LinearLayout internalWrapper = new LinearLayout(getContext());
        internalWrapper.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        internalWrapper.setOrientation(LinearLayout.HORIZONTAL);
        addView(internalWrapper);
        // this.mItems = items;
        for (int i = 0; i < 10; i++) {
            ImageView im = new ImageView(getContext());
            im.setImageResource(R.drawable.aaaa);
            im.setScaleType(ScaleType.CENTER_INSIDE);
            im.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));


            internalWrapper.addView(im);
        }
    }
}

And MainActivity:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        HomeFeatureLayout home = new HomeFeatureLayout(this);
        home.setFeatureItems();
        home.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        setContentView(home);

    }

Why are there blank spaces between each 2 images?

  • 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-09T11:48:14+00:00Added an answer on June 9, 2026 at 11:48 am

    I had to create my own view and extend ImageView, then override OnMeasure method, with the help of THIS question:

    public class myImageView extends ImageView {
    
        public myImageView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            MeasureSpec.getSize(widthMeasureSpec);
            MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
    
            setLayoutParams(new LinearLayout.LayoutParams(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)));
    
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    
        public int measureWidth(int measureSpec) {
            int result = 0;
            int specMode = MeasureSpec.getMode(measureSpec);
            int specSize = MeasureSpec.getSize(measureSpec);
            Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            int screenWidth = display.getWidth();
    
            if (specMode == MeasureSpec.EXACTLY)
                // We were told how big to be
                result = specSize;
            else {
                // Measure the view
                result = screenWidth;
                if (specMode == MeasureSpec.AT_MOST)
                    // Respect AT_MOST value if that was what is called for by measureSpec
                    result = Math.min(result, specSize);
            }
    
            return result;
        }
    
        public int measureHeight(int measureSpec) {
            int result = 0;
            int specMode = MeasureSpec.getMode(measureSpec);
            int specSize = MeasureSpec.getSize(measureSpec);
            Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            int screenHeight = display.getHeight();
    
            if (specMode == MeasureSpec.EXACTLY)
                // We were told how big to be
                result = specSize;
            else {
                // Measure the view
                result = screenHeight;
                if (specMode == MeasureSpec.AT_MOST)
                    // Respect AT_MOST value if that was what is called for by measureSpec
                    result = Math.min(result, specSize);
            }
    
            return result;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HorizontalScrollView that has lots of views and images inside it. The
I have the following HorizontalScrollView with 2 custom views. For some reason it doesn't
Hi guyzz I have TabActivity as following simple code public class TabhostActivity extends Activity{
I have created one custom view that contains the horizontalscrollview. Now when i changes
I have created one custom view that contains the horizontalscrollview. Now when i changes
I have a HorizontalScrollView in Android that looks like the following in the xml.
I have a tricky problem related to synchronized scrolling of two different views. I've
I have HorizontalScrollView with child Layout inside. After adding view into child layout I
I have a HorizontalScrollView with some buttons, I am trying to stretch these buttons
I have list items that have a HorizontalScrollView in each of them. Hence, 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.