Example usage for android.widget RelativeLayout CENTER_VERTICAL

List of usage examples for android.widget RelativeLayout CENTER_VERTICAL

Introduction

In this page you can find the example usage for android.widget RelativeLayout CENTER_VERTICAL.

Prototype

int CENTER_VERTICAL

To view the source code for android.widget RelativeLayout CENTER_VERTICAL.

Click Source Link

Document

Rule that centers the child vertically with respect to the bounds of its RelativeLayout parent.

Usage

From source file:com.bangqu.eshow.view.sliding.ESSlidingPlayView.java

/**
 * ???View./* w ww .  j a v  a  2s.  com*/
 *
 * @param context the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new ESInnerViewPager(context);
    //ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    //
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new ESViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPlayView.java

/**
 * ???View./*www.j a v a 2  s  .  co  m*/
 *
 * @param context the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    //ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    //
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.ab.view.sliding.AbSlidingPlayView.java

/**
 * ???View.//  w ww .  j  ava 2s.  co  m
 *
 * @param context the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    //ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    //
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    displayImage = AbFileUtil.getBitmapFromSrc("image/play_display.png");
    hideImage = AbFileUtil.getBitmapFromSrc("image/play_hide.png");

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.tony.selene.sliding.AbSlidingPlayView.java

/**
 * ???View./*from   w w w.ja  v a 2 s  .c  o  m*/
 *
 * @param context
 *            the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    // ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    // 
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.wll.main.widget.AbSlidingPlayView.java

/**
 * ???View.//from ww  w  .j a va2  s. c o  m
 *
 * @param context
 *            the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    // ViewPager,fragmentsetId()id
    mViewPager.setId(getResources().getInteger(R.integer.id_viewPager));
    // 
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    //      displayImage = AbFileUtil.getBitmapFromSrc("image/play_display.png");
    //      hideImage = AbFileUtil.getBitmapFromSrc("image/play_hide.png");

    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.mipmap.d2);
    Bitmap bm2 = BitmapFactory.decodeResource(context.getResources(), R.mipmap.d1);
    displayImage = bm;
    hideImage = bm2;

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.example.de.taomi2.mediachooser.activity.BucketHomeFragmentActivity.java

@SuppressLint("ResourceAsColor")
@Override//from   w  w w  .j  a  v a  2 s  .c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_home_media_chooser);

    headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar);
    headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar);
    headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView);
    headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView);
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);

    headerBarTitle.setText(getResources().getString(R.string.video));
    headerBarCamera.setBackgroundResource(R.drawable.ic_video_unselect_from_media_chooser_header_bar);
    headerBarCamera.setTag(getResources().getString(R.string.video));

    headerBarBack.setOnClickListener(clickListener);
    headerBarCamera.setOnClickListener(clickListener);
    headerBarDone.setOnClickListener(clickListener);

    if (!MediaChooserConstants.showCameraVideo) {
        headerBarCamera.setVisibility(View.GONE);
    }

    mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent);

    if (MediaChooserConstants.showVideo) {
        mTabHost.addTab(
                mTabHost.newTabSpec("tab2")
                        .setIndicator(getResources().getString(R.string.videos_tab) + "      "),
                BucketVideoFragment.class, null);
    }

    if (MediaChooserConstants.showImage) {
        mTabHost.addTab(
                mTabHost.newTabSpec("tab1")
                        .setIndicator(getResources().getString(R.string.images_tab) + "      "),
                BucketImageFragment.class, null);
    }

    mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color));

    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {

        View childView = mTabHost.getTabWidget().getChildAt(i);
        TextView textView = (TextView) childView.findViewById(android.R.id.title);

        if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) {

            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.CENTER_VERTICAL);
            params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
            params.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
            textView.setLayoutParams(params);

        } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams();
            params.gravity = Gravity.CENTER;
            textView.setLayoutParams(params);
        }
        textView.setTextColor(getResources().getColor(R.color.tabs_title_color));
        textView.setTextSize(convertDipToPixels(10));
    }

    ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
            .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
    ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
            .setTextColor(Color.WHITE);

    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {

            android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
            BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1");
            BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2");
            android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

            if (tabId.equalsIgnoreCase("tab1")) {

                headerBarTitle.setText(getResources().getString(R.string.image));
                headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button);
                headerBarCamera.setTag(getResources().getString(R.string.image));

                if (imageFragment == null) {
                    BucketImageFragment newImageFragment = new BucketImageFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1");

                } else {

                    if (videoFragment != null) {
                        fragmentTransaction.hide(videoFragment);
                    }

                    fragmentTransaction.show(imageFragment);

                }
                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);

            } else {
                headerBarTitle.setText(getResources().getString(R.string.video));
                headerBarCamera.setBackgroundResource(R.drawable.selector_video_button);
                headerBarCamera.setTag(getResources().getString(R.string.video));

                if (videoFragment == null) {

                    final BucketVideoFragment newVideoFragment = new BucketVideoFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2");

                } else {

                    if (imageFragment != null) {
                        fragmentTransaction.hide(imageFragment);
                    }

                    fragmentTransaction.show(videoFragment);
                }

                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));

            }

            fragmentTransaction.commit();
        }
    });

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) headerBarCamera.getLayoutParams();
    params.height = convertDipToPixels(40);
    params.width = convertDipToPixels(40);
    headerBarCamera.setLayoutParams(params);
    headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE);
    headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15),
            convertDipToPixels(15));

}

From source file:com.lxh.util.pullview.AbSlidingPlayView.java

/**
 * ???View./*from ww  w  .  j av  a  2s  .  co m*/
 *
 * @param context
 *            the context
 */
public void initView(Context context) {
    this.context = context;
    navLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    this.setOrientation(LinearLayout.VERTICAL);

    RelativeLayout mRelativeLayout = new RelativeLayout(context);

    mViewPager = new AbInnerViewPager(context);
    // ViewPager,fragmentsetId()id
    mViewPager.setId(1985);
    // 
    mNavLayoutParent = new LinearLayout(context);
    mNavLayoutParent.setPadding(0, 5, 0, 5);
    navLinearLayout = new LinearLayout(context);
    navLinearLayout.setPadding(15, 1, 15, 1);
    navLinearLayout.setVisibility(View.INVISIBLE);
    mNavLayoutParent.addView(navLinearLayout,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mRelativeLayout.addView(mViewPager, lp1);

    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mRelativeLayout.addView(mNavLayoutParent, lp2);
    addView(mRelativeLayout,
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    displayImage = FileUtil.getBitmapFromSrc("image/play_display.png");
    hideImage = FileUtil.getBitmapFromSrc("image/play_hide.png");

    mListViews = new ArrayList<View>();
    mAbViewPagerAdapter = new AbViewPagerAdapter(context, mListViews);
    mViewPager.setAdapter(mAbViewPagerAdapter);
    mViewPager.setFadingEdgeLength(0);
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            makesurePosition();
            onPageSelectedCallBack(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageScrolledCallBack(position);
        }

    });

}

From source file:com.learnncode.mediachooser.activity.BucketHomeFragmentActivity.java

@SuppressLint("ResourceAsColor")
@Override/*  w  ww .  ja  v  a 2 s .  c o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_home_media_chooser);

    headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar);
    headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar);
    headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView);
    headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView);
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);

    headerBarTitle.setText(getResources().getString(R.string.video));
    headerBarCamera.setBackgroundResource(R.drawable.ic_video_unselect_from_media_chooser_header_bar);
    headerBarCamera.setTag(getResources().getString(R.string.video));

    headerBarBack.setOnClickListener(clickListener);
    headerBarCamera.setOnClickListener(clickListener);
    headerBarDone.setOnClickListener(clickListener);

    if (!MediaChooserConstants.showCameraVideo) {
        headerBarCamera.setVisibility(View.GONE);
    }

    mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent);

    if (MediaChooserConstants.showVideo) {
        mTabHost.addTab(
                mTabHost.newTabSpec("tab2")
                        .setIndicator(getResources().getString(R.string.videos_tab) + "      "),
                BucketVideoFragment.class, null);
    }

    if (MediaChooserConstants.showImage) {
        mTabHost.addTab(
                mTabHost.newTabSpec("tab1")
                        .setIndicator(getResources().getString(R.string.images_tab) + "      "),
                BucketImageFragment.class, null);
    }

    mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color));

    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {

        View childView = mTabHost.getTabWidget().getChildAt(i);
        TextView textView = (TextView) childView.findViewById(android.R.id.title);

        if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) {

            RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) textView
                    .getLayoutParams();
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.CENTER_VERTICAL);
            params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
            params.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
            textView.setLayoutParams(params);

        } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) textView
                    .getLayoutParams();
            params.gravity = Gravity.CENTER;
            textView.setLayoutParams(params);
        }
        textView.setTextColor(getResources().getColor(R.color.tabs_title_color));
        textView.setTextSize(convertDipToPixels(10));
    }

    ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
            .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
    ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
            .setTextColor(Color.WHITE);

    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {

            android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
            BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1");
            BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2");
            android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

            if (tabId.equalsIgnoreCase("tab1")) {

                headerBarTitle.setText(getResources().getString(R.string.image));
                headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button);
                headerBarCamera.setTag(getResources().getString(R.string.image));

                if (imageFragment == null) {
                    BucketImageFragment newImageFragment = new BucketImageFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1");

                } else {

                    if (videoFragment != null) {
                        fragmentTransaction.hide(videoFragment);
                    }

                    fragmentTransaction.show(imageFragment);

                }
                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);

            } else {
                headerBarTitle.setText(getResources().getString(R.string.video));
                headerBarCamera.setBackgroundResource(R.drawable.selector_video_button);
                headerBarCamera.setTag(getResources().getString(R.string.video));

                if (videoFragment == null) {

                    final BucketVideoFragment newVideoFragment = new BucketVideoFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2");

                } else {

                    if (imageFragment != null) {
                        fragmentTransaction.hide(imageFragment);
                    }

                    fragmentTransaction.show(videoFragment);
                }

                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));

            }

            fragmentTransaction.commit();
        }
    });

    RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) headerBarCamera
            .getLayoutParams();
    params.height = convertDipToPixels(40);
    params.width = convertDipToPixels(40);
    headerBarCamera.setLayoutParams(params);
    headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE);
    headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15),
            convertDipToPixels(15));

}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

public void createMessage(ViewGroup l, String text, String button, View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(getActivity());
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    LinearLayout l2 = new LinearLayout(getActivity());
    l2.setOrientation(LinearLayout.VERTICAL);
    RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutparams.addRule(RelativeLayout.CENTER_VERTICAL);
    l2.setLayoutParams(layoutparams);//w  ww  . jav a 2s  .co  m
    l2.setGravity(Gravity.CENTER_HORIZONTAL);

    TextView tv = new TextView(getActivity());
    LinearLayout.LayoutParams tvparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(tvparams);
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    l2.addView(tv);

    if (button != null) {
        Button b = new Button(getActivity());
        LinearLayout.LayoutParams bparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        bparams.setMargins(toPixels(4), toPixels(0), toPixels(4), toPixels(4));
        b.setLayoutParams(bparams);
        b.setId(R.id.reload_button);
        b.setText(button);
        b.setTextSize(23);
        b.setAllCaps(false);
        b.setTypeface(null, Typeface.NORMAL);
        b.setOnClickListener(onclick);
        l2.addView(b);
    }

    r.addView(l2);
    l.addView(r);
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void createButtonWithText(Activity activity, ViewGroup l, String text, String button,
        View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(activity);
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    TextView tv = new TextView(activity);
    RelativeLayout.LayoutParams tvparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvparams.addRule(RelativeLayout.ABOVE, R.id.reload_button);
    tvparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    tv.setLayoutParams(tvparams);//from  ww w  .  j  a  v a2s .  c  o  m
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    r.addView(tv);

    Button b = new Button(activity);
    RelativeLayout.LayoutParams bparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    bparams.addRule(RelativeLayout.CENTER_VERTICAL);
    bparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    b.setLayoutParams(bparams);
    b.setId(R.id.reload_button);
    b.setText(button);
    b.setTextSize(23);
    b.setAllCaps(false);
    b.setTypeface(null, Typeface.NORMAL);
    b.setOnClickListener(onclick);
    r.addView(b);

    l.addView(r);
}