Android ViewPager 左右滑动-1

Store extends ActivityGroup implements OnClickListener


private ViewPager viewPager;
    private ArrayList<View> pageViews;
    private RadioGroup radioGroup;
    private String title[] = { "A", "B", "C", "D", "E", "F" };
    private LinearLayout linearLayout;
    private final int height = 70;
    private ArrayList<TextView> textViews;
    private HorizontalScrollView horizontalScrollView;
   
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);
       
        linearLayout = (LinearLayout) findViewById(R.id.ll_main);
        viewPager = (ViewPager) findViewById(R.id.pager);
        horizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView);
        InItTitle1();
        setSelector(0);
        InItView();
        viewPager.setAdapter(new myPagerView());
        viewPager.clearAnimation();
        viewPager.setOnPageChangeListener(new OnPageChangeListener() {

            public void onPageSelected(int arg0) {
                setSelector(arg0);
            }

            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            public void onPageScrollStateChanged(int arg0) {

            }
        });
    }
   
    /***
     * init title
     */
    void InItTitle() {
        int width = getWindowManager().getDefaultDisplay().getWidth() / 5;
        for (int i = 0; i < title.length; i++) {
            RadioButton radioButton = new RadioButton(this, null,
                    R.style.radioButton);
            radioButton.setText(title[i]);
            radioButton.setTextSize(17);
            radioButton.setTextColor(R.color.black);
            radioButton.setWidth(width);
            radioButton.setHeight(height);
            radioButton.setGravity(Gravity.CENTER);
            radioGroup.addView(radioButton);
        }
    }
   
    /***
     * init title
     */
    void InItTitle1() {
        textViews = new ArrayList<TextView>();
        int width = getWindowManager().getDefaultDisplay().getWidth() / 5;
        int height = 70;
        for (int i = 0; i < title.length; i++) {
            TextView textView = new TextView(this);
            textView.setText(title[i]);
            textView.setTextSize(17);
            textView.setTextColor(R.color.black);
            textView.setWidth(width);
            textView.setHeight(height - 30);
            textView.setGravity(Gravity.CENTER);
            textView.setId(i);
            textView.setOnClickListener(this);
            textViews.add(textView);
            // 分割线
            View view = new View(this);
            LinearLayout.LayoutParams layoutParams = new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            layoutParams.width = 1;
            layoutParams.height = height - 40;
            layoutParams.gravity = Gravity.CENTER;
            view.setLayoutParams(layoutParams);
            view.setBackgroundColor(R.color.gray);
            linearLayout.addView(textView);
            if (i != title.length - 1) {
                linearLayout.addView(view);
            }

        }
    }

你可能感兴趣的:(viewpager)