Jezzy ViewPager在活动类中显示片段

时间:2015-05-14 10:19:11

标签: android android-fragments android-viewpager

所以情况就是这样,我有一个扩展活动的类,其中有一个this ViewPager,用于显示空白布局并在每次滑动时更改其颜色。 我在这里要做的是显示一个片段,而不是通过滑动更改其内容,我该怎么做?

public Object instantiateItem(ViewGroup container, final int position) {
        TextView text = new TextView(OfferActivity.this);
        text.setGravity(Gravity.CENTER);
        text.setTextSize(30);
        text.setTextColor(Color.WHITE);
        text.setText("Page " + position);
        text.setPadding(30, 30, 30, 30);
        int bg = Color.rgb((int) Math.floor(Math.random()*128)+64, 
                (int) Math.floor(Math.random()*128)+64,
                (int) Math.floor(Math.random()*128)+64);
        text.setBackgroundColor(bg);
        container.addView(text, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mJazzy.setObjectForPosition(text, position);
        return text;
    }

0 个答案:

没有答案