PagerView overlapping PagerTabStrip / PagerTitleStrip
Posted
by
user1256169
on Stack Overflow
See other posts from Stack Overflow
or by user1256169
Published on 2012-10-14T03:20:47Z
Indexed on
2012/10/14
3:37 UTC
Read the original article
Hit count: 417
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);
}
}
}
Edit: Adding a screenshot of the problem:
© Stack Overflow or respective owner