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

  • Home
  • SEARCH
  • 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 8505327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:17:12+00:00 2026-06-11T02:17:12+00:00

ViewPager does not wrap its height to its content. For my layout I need

  • 0

ViewPager does not wrap its height to its content. For my layout I need to set the height dynamically because it is nested in other layouts.
Therefore I created a ScrollView as content of the ViewPager and check its height in onCreate method of the Fragment, but the ScrollView has always the same size.
How can I wrap height of the ViewPager to fit to its content?

        final ScrollView sv = (ScrollView) v.findViewById(R.id.sv);

        ViewTreeObserver vto = sv.getViewTreeObserver(); 
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
            @Override 
            public void onGlobalLayout() {

                int height = sv.getMeasuredHeight();
                //always same height independent of content height
                //need to resize ViewPager



                ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) mPager.getLayoutParams();
                params.height = height;
                mPager.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-11T02:17:14+00:00Added an answer on June 11, 2026 at 2:17 am

    Tried a lot of things, finally got it.
    -initially set the ViewPager to a big height to fit all possible content and not to make its height reduced
    -had to nest 2 LinearLayout to get the correct height.
    hth

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

Sidebar

Related Questions

When its giving an error saying AppHelper does not exist, am I missing any
I'm trying to set the text of a TextView in a layout using ViewPager.
Does the ViewPager have to be the only object present inside the activity layout?
I made a viewPager with three layouts on every page... And i want to
CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'UTEPSA'
I'm using SwipeyTabs in my application. I'm not sure how to fill tabs content.
I saw this ViewPager, compatibility package and ice cream sandwich and that Does the
What my code does: Here's my code which for viewpager that swipes between xml
my viewpager currently only re-renders views that are two views away from what is
I developd a viewpager with custom list views in android. I followed the tutorial

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.