List of usage examples for android.widget RelativeLayout CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.widget RelativeLayout CENTER_HORIZONTAL.
Click Source Link
From source file:Main.java
public static RelativeLayout.LayoutParams getViewPositionParams(String alignment, int offsetX, int offsetY, int w, int h, int below) { // create a layout params RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h); // alignment vertical rule if (alignment.contains("top")) { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); } else if (alignment.contains("bottom")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } else {/*from www . j a va 2 s .c o m*/ params.addRule(RelativeLayout.CENTER_VERTICAL); } // alignment horizontal rule if (alignment.contains("left")) { params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); } else if (alignment.contains("right")) { params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { params.addRule(RelativeLayout.CENTER_HORIZONTAL); } // set below if (below > 0) { params.addRule(RelativeLayout.BELOW, below); } return params; }
From source file:me.ziccard.secureit.fragment.EmptyFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) { mContent = savedInstanceState.getString(CONTENT); }/*from www . j a v a 2 s .co m*/ TextView text = new TextView(getActivity()); text.setGravity(Gravity.CENTER); text.setText(mContent); text.setTextSize(20 * getResources().getDisplayMetrics().density); RelativeLayout layout = new RelativeLayout(getActivity()); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); layout.setGravity(Gravity.CENTER); RelativeLayout alert = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.leftMargin = 20; params.rightMargin = 20; params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_IN_PARENT); alert.setLayoutParams(params); alert.setBackgroundResource(R.drawable.red_back); alert.setPadding(30, 0, 30, 0); alert.addView(text); layout.addView(alert); return layout; }
From source file:Main.java
public static void applyAttributes(JSONObject jsonObject, RelativeLayout.LayoutParams layoutParams) throws JSONException { applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, TO_LEFT_OF, RelativeLayout.LEFT_OF); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, TO_RIGHT_OF, RelativeLayout.RIGHT_OF); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, BELOW, RelativeLayout.BELOW); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ABOVE, RelativeLayout.ABOVE); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_LEFT, RelativeLayout.ALIGN_LEFT); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_RIGHT, RelativeLayout.ALIGN_RIGHT); applyRelativeLayoutRuleIfExists(jsonObject, layoutParams, ALIGN_TOP, RelativeLayout.ALIGN_TOP); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_TOP, RelativeLayout.ALIGN_PARENT_TOP); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_BOTTOM, RelativeLayout.ALIGN_PARENT_BOTTOM); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_RIGHT, RelativeLayout.ALIGN_PARENT_RIGHT); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_LEFT, RelativeLayout.ALIGN_PARENT_LEFT); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_BASELINE, RelativeLayout.ALIGN_BASELINE); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, ALIGN_PARENT_TOP, RelativeLayout.ALIGN_PARENT_TOP); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_HORIZONTAL, RelativeLayout.CENTER_HORIZONTAL); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_IN_PARENT, RelativeLayout.CENTER_IN_PARENT); applyRelativeLayoutBooleanIfExists(jsonObject, layoutParams, CENTER_VERTICAL, RelativeLayout.CENTER_VERTICAL); }
From source file:com.learnncode.tabsample.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.tab_one)), TabOneFrgment.class, null); mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.tab_two)), TabTwoFrgment.class, null); mTabHost.setCurrentTabByTag("tag2"); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { TextView textView = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) textView .getLayoutParams();//w ww .j a va2 s . c om params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title).setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) textView .getLayoutParams(); params.gravity = Gravity.CENTER; mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title).setLayoutParams(params); } } mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); TabOneFrgment tabOneFrgment = (TabOneFrgment) fragmentManager.findFragmentByTag("tab1"); TabTwoFrgment tabTwoFrgment = (TabTwoFrgment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { if (tabOneFrgment != null) { if (tabTwoFrgment != null) { fragmentTransaction.hide(tabTwoFrgment); } fragmentTransaction.show(tabOneFrgment); } } else { if (tabTwoFrgment != null) { if (tabOneFrgment != null) { fragmentTransaction.hide(tabOneFrgment); } fragmentTransaction.show(tabTwoFrgment); } } fragmentTransaction.commit(); } }); }
From source file:dev.nick.tiles.tile.TileView.java
protected RelativeLayout.LayoutParams generateCenterParams(int w, int h) { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); return params; }
From source file:csms19.inapp.msg.customgallery.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override/*from ww w . j av a2s. com*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_home_customgallery); String name = getIntent().getStringExtra("username"); mediasellistnr = this; chooserheadertext = (TextView) findViewById(R.id.chooserheadertext); chooserhbackbtnlay = (RelativeLayout) findViewById(R.id.chooserhbackbtnlay); if (name != null) chooserheadertext.setText(name); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); chooserhbackbtnlay.setOnClickListener(clickListener); mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); if (MediaChooserConstants.showVideo) { mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Videos" + " "), BucketVideoFragment.class, null); } // ///////Images set right tab so write below if (MediaChooserConstants.showImage) { mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Images" + " "), 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.black)); textView.setTextSize(convertDipToPixels(10)); } ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); 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")) { 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(Color.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); } else { 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.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); } fragmentTransaction.commit(); } }); }
From source file:es.uma.lcc.lockpic.SelectorActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button btnForward, btnBack, btnFaces; RelativeLayout layout = new RelativeLayout(this); layout.setBackgroundResource(R.drawable.background_gradient); mPath = getIntent().getStringExtra("path"); SelectorActivityBundle bundle = (SelectorActivityBundle) getLastCustomNonConfigurationInstance(); if (bundle != null) { mDrawView = new DrawView(this, mPath, false); mDrawView.setRectangles(bundle.getRectangles()); mDrawView.setViewMode(bundle.getViewMode()); mDrawView.setAspectRate(bundle.getAspectRate()); } else {//from w w w .j av a 2s . co m mDrawView = new DrawView(this, mPath, true); } mDrawView.setId(1); RelativeLayout.LayoutParams lpDrawView = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpDrawView.addRule(RelativeLayout.CENTER_VERTICAL); mDrawView.setLayoutParams(lpDrawView); layout.addView(mDrawView, lpDrawView); btnForward = new Button(this); btnForward.setText(R.string.selectorForwardButton); btnForward.setId(2); btnForward.setOnClickListener(new forwardButtonListener()); RelativeLayout.LayoutParams lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lpButton.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layout.addView(btnForward, lpButton); btnBack = new Button(this); btnBack.setText(R.string.selectorBackButton); btnBack.setId(3); btnBack.setOnClickListener(new backButtonListener()); lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lpButton.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layout.addView(btnBack, lpButton); btnFaces = new Button(this); btnFaces.setText(R.string.facesButton); btnFaces.setId(4); btnFaces.setOnClickListener(new FacesButtonListener()); if (!isViewSelectingRegions()) btnFaces.setVisibility(View.INVISIBLE); lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lpButton.addRule(RelativeLayout.CENTER_HORIZONTAL); layout.addView(btnFaces, lpButton); setContentView(layout); }
From source file:net.pocketmagic.android.carousel.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //no keyboard unless requested by user getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // compute screen size and scaling Singleton.getInstance().InitGUIFrame(this); int padding = m_Inst.Scale(10); // create the interface : full screen container RelativeLayout panel = new RelativeLayout(this); panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); panel.setPadding(padding, padding, padding, padding); panel.setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { Color.WHITE, Color.GRAY })); setContentView(panel);/*w ww.j a v a 2s .c o m*/ // copy images from assets to sdcard AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma1.png", "plasma1.png", false); AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma2.png", "plasma2.png", false); AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma3.png", "plasma3.png", false); AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma4.png", "plasma4.png", false); //Create carousel view documents ArrayList<CarouselDataItem> Docus = new ArrayList<CarouselDataItem>(); for (int i = 0; i < 1000; i++) { CarouselDataItem docu; if (i % 4 == 0) docu = new CarouselDataItem("/mnt/sdcard/plasma1.png", 0, "First Image " + i); else if (i % 4 == 1) docu = new CarouselDataItem("/mnt/sdcard/plasma2.png", 0, "Second Image " + i); else if (i % 4 == 2) docu = new CarouselDataItem("/mnt/sdcard/plasma3.png", 0, "Third Image " + i); else docu = new CarouselDataItem("/mnt/sdcard/plasma4.png", 0, "4th Image " + i); Docus.add(docu); } // add the serach filter EditText etSearch = new EditText(this); etSearch.setHint("Search your documents"); etSearch.setSingleLine(); etSearch.setTextColor(Color.BLACK); etSearch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0); AppUtils.AddView(panel, etSearch, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] { new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_TOP } }, -1, -1); etSearch.addTextChangedListener((TextWatcher) this); // add logo TextView tv = new TextView(this); tv.setTextColor(Color.BLACK); tv.setText("www.pocketmagic.net"); AppUtils.AddView(panel, tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] { new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_BOTTOM } }, -1, -1); // create the carousel CarouselView coverFlow = new CarouselView(this); // create adapter and specify device independent items size (scaling) // for more details see: http://www.pocketmagic.net/2013/04/how-to-scale-an-android-ui-on-multiple-screens/ m_carouselAdapter = new CarouselViewAdapter(this, Docus, m_Inst.Scale(400), m_Inst.Scale(300)); coverFlow.setAdapter(m_carouselAdapter); coverFlow.setSpacing(-1 * m_Inst.Scale(150)); coverFlow.setSelection(Integer.MAX_VALUE / 2, true); coverFlow.setAnimationDuration(1000); coverFlow.setOnItemSelectedListener((OnItemSelectedListener) this); AppUtils.AddView(panel, coverFlow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, new int[][] { new int[] { RelativeLayout.CENTER_IN_PARENT } }, -1, -1); }
From source file:com.nicolls.ablum.activity.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override/*from w ww . j av 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); mediaType = getIntent().getStringExtra("mediaType"); List<String> pathList = getIntent().getStringArrayListExtra("pathList"); 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); headerBarBack.setOnClickListener(clickListener); headerBarCamera.setOnClickListener(clickListener); headerBarDone.setOnClickListener(clickListener); headerBarDone.setVisibility(View.INVISIBLE); mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.images_tab) + " "), BucketImageFragment.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.videos_tab) + " "), BucketVideoFragment.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) { // Toast.makeText(getApplicationContext(),tabId,Toast.LENGTH_LONG).show(); 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)); if (TextUtils.equals(mediaType, MediaChooserConstants.TYPE_PHOTO)) {//? mTabHost.setCurrentTab(0); headerBarTitle.setText(getResources().getString(R.string.image)); headerBarCamera.setTag(getResources().getString(R.string.image)); headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button); } else { mTabHost.setCurrentTab(1); headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setTag(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.selector_video_button); } }
From source file:com.bangqu.eshow.view.sliding.ESSlidingPlayView.java
/** * ???View./*w w w .j a va 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 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); } }); }