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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:57:53+00:00 2026-06-12T20:57:53+00:00

I’ve been trying for about a week to get my PagerView not to overlap

  • 0

I’ve been trying for about a week to get my PagerView not to overlap the TitleStrip.

I’ve tried absolutely everything I can think of, and one StackOverflow question that looked like the same question, had an answer that wasn’t applicable.

It appears that both the PagerTitleStrip and the TextView start at 0,0 (left,top)

Any help would be appreciated. Note that I can’t use any XML (inc Layout.xml) so it’s all done programatically.

Here’s a full working example of my problem:

package com.example.projname;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyPagerAdapter myPagerAdapter = new MyPagerAdapter();
        PagerTabStrip myPagerTabStrip = new PagerTabStrip(this);
        myPagerTabStrip.setGravity(Gravity.TOP);
        ViewPager viewPager = new ViewPager(this);
        viewPager.addView(myPagerTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        viewPager.setAdapter(myPagerAdapter);
        setContentView(viewPager);
    }

    class MyPagerAdapter extends PagerAdapter {
        public final String[] Titles = {
            "Title One",
            "Title Two",
            "Title Three",
            "Title Four",
            "Title Five"
        };

        @Override
        public int getCount() {
            return Titles.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return (view == object);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return Titles[position];
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            TextView textView = new TextView(getApplicationContext());
            String myString = new String("Page " + (position + 1) + "\r\n");
            textView.setText(myString + myString + myString + myString + myString + myString);
            container.addView(textView);
            return textView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}

Edit1: Adding a screenshot of the problem:
The text Page1 is shown much higher than it should be

Edit2: Updating question with answer (in-case anyone tries this in the future

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LayoutParams layoutParams = new LayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    layoutParams.width = LayoutParams.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    PagerTabStrip myPagerTabStrip = new PagerTabStrip(this);
    MyPagerAdapter myPagerAdapter = new MyPagerAdapter();       
    ViewPager viewPager = new ViewPager(this);
    viewPager.addView(myPagerTabStrip, layoutParams);
    viewPager.setAdapter(myPagerAdapter);
    setContentView(viewPager);
}
  • 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-12T20:57:54+00:00Added an answer on June 12, 2026 at 8:57 pm

    Note that I can’t use any XML

    Why?

    Any help would be appreciated.

    Try a version of addView() that takes a LayoutParams object as a parameter, and use an instance of ViewPager.LayoutParams. Also, use the gravity field on the ViewPager.LayoutParams instead of setGravity().

    If that does not help, temporarily set up a ViewPager and PagerTitleStrip in XML (e.g., in a separate project) and examine the results in Hierarchy View to see how the XML approach constructs matters, so you can try to replicate it.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.