Example usage for android.widget RelativeLayout CENTER_HORIZONTAL

List of usage examples for android.widget RelativeLayout CENTER_HORIZONTAL

Introduction

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

Prototype

int CENTER_HORIZONTAL

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

Click Source Link

Document

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

Usage

From source file:com.gokuai.yunkuandroidsdk.compat.v2.UrlTouchImageView.java

@SuppressWarnings("deprecation")
protected void init() {

    mImageView = new TouchImageView(mContext);

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.FILL_PARENT);
    mImageView.setLayoutParams(params);//w w  w  .j a  v  a 2s  . c o  m
    this.addView(mImageView);

    mImageView.setVisibility(GONE);

    mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleInverse);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(params);
    mProgressBar.setIndeterminate(false);
    this.addView(mProgressBar);

    mTextView = new TextView(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mTextView.setLayoutParams(params);
    int left = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_left);
    int top = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_top);
    int right = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_right);
    int bottom = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_bottom);
    mTextView.setPadding(left, top, right, bottom);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setTextColor(Color.WHITE);
    mTextView.setText(R.string.tip_is_preparing_for_data);
    mTextView.setVisibility(View.GONE);
    this.addView(mTextView);

    mButton = new Button(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mButton.setLayoutParams(params);
    mButton.setGravity(Gravity.CENTER);
    mButton.setText(R.string.tip_image_button);
    mButton.setTextColor(Color.WHITE);
    mButton.setBackgroundResource(R.drawable.btn_check_image);
    mButton.setVisibility(View.GONE);
    this.addView(mButton);

    mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mImageUrlTask = new AsyncTask<Void, Integer, Bitmap>() {

                @Override
                protected Bitmap doInBackground(Void... voids) {
                    if (mFileData != null) {
                        FileData fileData = FileDataManager.getInstance()
                                .getFileInfoSync(mFileData.getFullpath());

                        return getOriImage(fileData, new ParamsCallBack() {
                            @Override
                            public void callBack(Object obj) {
                                publishProgress((int) obj);
                            }
                        });

                    } else {
                        return null;
                    }

                }

                @Override
                protected void onProgressUpdate(Integer... values) {
                    super.onProgressUpdate(values);
                    mButton.setVisibility(GONE);
                    mTextView.setVisibility(VISIBLE);
                    mProgressBar.setVisibility(VISIBLE);
                    if (values[0] == -1) {
                        mTextView.setText(mContext.getString(R.string.tip_is_loading));
                    } else {
                        mTextView.setText(values[0] + " %");
                    }
                }

                @Override
                protected void onPostExecute(Bitmap bitmap) {
                    super.onPostExecute(bitmap);

                    if (mImageView != null && mProgressBar != null) {
                        if (bitmap != null) {
                            mButton.setVisibility(GONE);
                            mImageView.setScaleType(ScaleType.MATRIX);
                            mImageView.setImageBitmap(bitmap);

                            mTextView.setVisibility(View.GONE);
                            mImageView.setVisibility(VISIBLE);
                            mProgressBar.setVisibility(GONE);

                        } else {
                            mButton.setVisibility(GONE);
                            mTextView.setVisibility(VISIBLE);
                            mTextView.setText(R.string.tip_open_image_failed);
                            mProgressBar.setVisibility(View.VISIBLE);
                        }
                    }

                }
            }.execute();
        }
    });

}

From source file:r2b.apps.view.base.BaseAbsListFragment.java

@Override
protected void initViews() {
    absListView = (AbsListView) getView().findViewById(android.R.id.list);

    emptyView = getEmptyView();// w ww. ja  v  a2  s.  c  om
    errorView = getErrorView();
    loadingView = getLoadingView();

    RelativeLayout.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lp.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout rl = new RelativeLayout(getActivity());
    rl.setLayoutParams(lp);

    if (emptyView != null) {
        rl.addView(emptyView);
    }
    if (errorView != null) {
        rl.addView(errorView);
    }
    if (loadingView != null) {
        rl.addView(loadingView);
    }

    ViewGroup parent = (ViewGroup) absListView.getParent();
    parent.addView(rl);
    absListView.setEmptyView(rl);

    showEmptyView();
}

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

/**
 * ???View.//from   w w w  .j av  a 2s  .  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: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);//ww  w  .  ja v  a 2 s .  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);
}

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

/**
 * ???View./*from  w  w w  .  jav 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);
    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.//  ww  w. 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.wll.main.widget.AbSlidingPlayView.java

/**
 * ???View./*from  w  ww. j av a2s .  co 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 2s .com
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   www . ja v  a  2  s.c  om
 *
 * @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/*from  ww  w. jav  a2 s. co 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));

}