List of usage examples for android.widget RelativeLayout CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.widget RelativeLayout CENTER_VERTICAL.
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 {/* w ww. java2 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: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 w w .j av a 2s. c o m 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: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 {/* w w w. j ava2s .com*/ 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:org.telegram.ui.ChangePhoneHelpActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); TLRPC.User user = UserConfig.getCurrentUser(); String value;/*from ww w .j av a2 s. c o m*/ if (user != null && user.phone != null && user.phone.length() != 0) { value = PhoneFormat.getInstance().format("+" + user.phone); } else { value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown); } actionBar.setTitle(value); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new RelativeLayout(context); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); RelativeLayout relativeLayout = (RelativeLayout) fragmentView; ScrollView scrollView = new ScrollView(context); relativeLayout.addView(scrollView); RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); scrollView.setLayoutParams(layoutParams3); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20)); scrollView.addView(linearLayout); ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.phone_change); linearLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setGravity(Gravity.CENTER_HORIZONTAL); //textView.setTextColor(0xff212121); try { textView.setText(AndroidUtilities .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp))); } catch (Exception e) { FileLog.e("tmessages", e); textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)); } linearLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; layoutParams2.leftMargin = AndroidUtilities.dp(20); layoutParams2.rightMargin = AndroidUtilities.dp(20); layoutParams2.topMargin = AndroidUtilities.dp(56); textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/); textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange)); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); textView.setBackground(context.getDrawable(R.drawable.list_selector)); linearLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; layoutParams2.leftMargin = AndroidUtilities.dp(20); layoutParams2.rightMargin = AndroidUtilities.dp(20); layoutParams2.topMargin = AndroidUtilities.dp(46); textView.setLayoutParams(layoutParams2); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { presentFragment(new ChangePhoneActivity(), true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); return fragmentView; }
From source file:touchgallery.UrlTouchImageView.java
@SuppressWarnings("deprecation") protected void init() { mImageView = new TouchImageView(mContext); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); mImageView.setLayoutParams(params);/*w ww . ja va2 s . c om*/ this.addView(mImageView); mImageView.setVisibility(GONE); mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleHorizontal); params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_VERTICAL); params.setMargins(30, 0, 30, 0); mProgressBar.setLayoutParams(params); mProgressBar.setIndeterminate(false); mProgressBar.setMax(100); this.addView(mProgressBar); }
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//ww 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_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:com.nicolls.ablum.activity.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override//from w ww. ja v a2 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:r2b.apps.view.base.BaseAbsListFragment.java
@Override protected void initViews() { absListView = (AbsListView) getView().findViewById(android.R.id.list); emptyView = getEmptyView();//from www.ja v a 2 s . com 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(); }