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:com.pdftron.pdf.controls.UserCropDialogFragment.java
private void initUI(final View view) { final FrameLayout layout = (FrameLayout) view.findViewById(R.id.layout_root); mPageNumberTextView = (TextView) view.findViewById(R.id.page_num_text_view); mLayoutName = layout.getTag().toString(); mDisablingOverlay = view.findViewById(R.id.disabling_overlay); mProgressBarHost = view.findViewById(R.id.progress_bar_host); mDisablingOverlay.setOnTouchListener(new View.OnTouchListener() { @Override//from w w w . j a v a 2 s . co m public boolean onTouch(View v, MotionEvent event) { return true; // ensure the user can't click buttons } }); mCropPageHost = (RelativeLayout) view.findViewById(R.id.page_crop_host); mCropImageBorder = view.findViewById(R.id.image_crop_border); mCropImageView = (com.edmodo.cropper.CropImageView) view.findViewById(R.id.image_crop_view); mCropImageView.setGuidelines(0); // off mCropImageBorder.setVisibility(View.GONE); mBlankPagePlaceholder = view.findViewById(R.id.blank_page_placeholder); mBlankPageSpinnerHost = (ContentLoadingRelativeLayout) view.findViewById(R.id.blank_page_progress_bar_host); if (mRemoveCropHelperMode) { View manualCropRoot = view.findViewById(R.id.manual_crop_root_layout); manualCropRoot.setVisibility(View.GONE); setCropBoxAndClose(); } else { mCropPageHost.postDelayed(new Runnable() { @Override public void run() { if (mIsActive) { if (mLayoutName.equals("layout-sw480dp-port") || mLayoutName.equals("layout-sw480dp-land")) { if (view.getWidth() < 540) { View buttonHost = view.findViewById(R.id.page_buttons_host); int[] location = new int[2]; buttonHost.getLocationInWindow(location); int buttonsLeft = location[0]; View pageNumText = view.findViewById(R.id.page_num_text_view); pageNumText.getLocationInWindow(location); int pageNumRight = location[0] + pageNumText.getWidth(); if (pageNumRight > buttonsLeft - 10) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) buttonHost .getLayoutParams(); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 0); } } } mCropImageBorder.setVisibility(View.VISIBLE); setPage(mCurrentPage); } } }, 200); // Extra delay to ensure that view has time to settle. post alone doesn't work. } getButtons(view); if (mDisablingOverlayShowing) { mDisablingOverlay.setVisibility(View.VISIBLE); } if (mSpinnerShowing) { mProgressBarHost.setVisibility(View.VISIBLE); } }
From source file:com.cloud.widget.viewpager.PagerSlidingTabStrip.java
/** * Modify by Cloud on 15/12/1./* w ww . ja v a2 s . co m*/ * TabViewViewGroup */ private void addTextTab(final int position, String title, float num, boolean hasIndicator, boolean hasNum, int tabNum) { relativeLayout = new RelativeLayout(getContext()); if (hasIndicator) { if (hasNum) { //title RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); titleText = new TextView(getContext()); titleText.setText(title); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleLp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); titleText.setLayoutParams(titleLp); // RelativeLayout.LayoutParams indicatorLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); indicatorText = new TextView(getContext()); indicatorText.setHeight(px2dip(getContext(), 50)); indicatorText.setWidth(px2dip(getContext(), screenWidth)); indicatorText.setText("" + String.valueOf(num)); indicatorText.setGravity(Gravity.CENTER); indicatorText.setSingleLine(); indicatorLp.topMargin = 5; indicatorLp.bottomMargin = 5; indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); indicatorText.setLayoutParams(indicatorLp); relativeLayout.addView(indicatorText); relativeLayout.addView(titleText); } else { //title RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); titleText = new TextView(getContext()); titleText.setText(title); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleText.setLayoutParams(titleLp); relativeLayout.addView(titleText); } } else { RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); titleText = new TextView(getContext()); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleText.setLayoutParams(titleLp); relativeLayout.addView(titleText); if (num % 1 == 0) { titleText.setText(title + "(" + String.valueOf((int) num) + ")"); } else { titleText.setText(title + "(" + String.valueOf(num) + ")"); } } if (num != 0 && hasIndicator && !hasNum) { // RelativeLayout.LayoutParams indicatorLp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); indicatorText = new TextView(getContext()); indicatorText.setHeight(px2dip(getContext(), 50)); indicatorText.setWidth(px2dip(getContext(), 50)); if (num % 1 == 0) { indicatorText.setText(String.valueOf((int) num)); } else { indicatorText.setText(String.valueOf(num)); } indicatorText.setGravity(Gravity.CENTER); indicatorText.setSingleLine(); indicatorText .setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.indicator_red_shape)); indicatorText.setTextAppearance(getContext(), indicatorNum); indicatorLp.topMargin = 10; if (tabNum == 4) { indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); } else { indicatorLp.leftMargin = screenWidth / 4 + screenWidth / 16; } indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); indicatorText.setLayoutParams(indicatorLp); relativeLayout.addView(indicatorText); } addTab(position, relativeLayout); }
From source file:fr.cph.stock.android.activity.AccountActivity.java
@Override public void displayError(JSONObject json) { boolean sessionError = ((StockTrackerApp) getApplication()).isSessionError(json); if (sessionError) { ((StockTrackerApp) getApplication()).loadErrorActivity(this, json); } else {// ww w . j a v a2 s. c o m errorView.setText(json.optString("error")); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) LayoutParams.WRAP_CONTENT, (int) LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.BELOW, errorView.getId()); params.addRule(RelativeLayout.CENTER_HORIZONTAL); totalValueView.setLayoutParams(params); menuItem.collapseActionView(); menuItem.setActionView(null); } }
From source file:com.luseen.spacenavigation.SpaceNavigationView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); /**/*from www . j a v a 2 s .c o m*/ * Restore current item index from savedInstance */ restoreCurrentItem(); /** * Trow exceptions if items size is greater than 4 or lesser than 2 */ if (spaceItems.size() < 2) { throw new NullPointerException("Your space item count must be greater than 1 ," + " your current items count is : " + spaceItems.size()); } if (spaceItems.size() > 4) { throw new IndexOutOfBoundsException( "Your items count maximum can be 4," + " your current items count is : " + spaceItems.size()); } /** * Get left or right content width */ contentWidth = (w - spaceNavigationHeight) / 2; /** * Removing all view for not being duplicated */ removeAllViews(); /** * Views initializations and customizing */ RelativeLayout mainContent = new RelativeLayout(context); RelativeLayout centreBackgroundView = new RelativeLayout(context); LinearLayout leftContent = new LinearLayout(context); LinearLayout rightContent = new LinearLayout(context); BezierView centreContent = buildBezierView(); FloatingActionButton fab = new FloatingActionButton(context); fab.setSize(FloatingActionButton.SIZE_NORMAL); fab.setBackgroundTintList(ColorStateList.valueOf(centreButtonColor)); fab.setImageResource(centreButtonIcon); fab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (spaceOnClickListener != null) spaceOnClickListener.onCentreButtonClick(); } }); /** * Set fab layout params */ LayoutParams fabParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); fabParams.addRule(RelativeLayout.CENTER_IN_PARENT); fabParams.setMargins(centreContentMargin, centreContentMargin, centreContentMargin, centreContentMargin); /** * Main content size */ LayoutParams mainContentParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mainContentHeight); mainContentParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Centre content size */ LayoutParams centreContentParams = new LayoutParams(centreContentWight, spaceNavigationHeight); centreContentParams.addRule(RelativeLayout.CENTER_HORIZONTAL); /** * Centre Background View content size and position */ LayoutParams centreBackgroundViewParams = new LayoutParams(centreContentWight, mainContentHeight); centreBackgroundViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL); centreBackgroundViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Left content size */ LayoutParams leftContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); leftContentParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); leftContentParams.addRule(LinearLayout.HORIZONTAL); /** * Right content size */ LayoutParams rightContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); rightContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rightContentParams.addRule(LinearLayout.HORIZONTAL); /** * Adding views background colors */ leftContent.setBackgroundColor(spaceBackgroundColor); rightContent.setBackgroundColor(spaceBackgroundColor); centreBackgroundView.setBackgroundColor(spaceBackgroundColor); /** * Adding view to centreContent */ centreContent.addView(fab, fabParams); /** * Adding views to mainContent */ mainContent.addView(leftContent, leftContentParams); mainContent.addView(rightContent, rightContentParams); /** * Adding views to mainView */ addView(centreBackgroundView, centreBackgroundViewParams); addView(centreContent, centreContentParams); addView(mainContent, mainContentParams); /** * Adding current space items to left and right content */ addSpaceItems(leftContent, rightContent); /** * Redraw main view to make subviews visible */ Utils.postRequestLayout(this); }
From source file:com.frostytornado.cordova.plugin.ad.admob.Util.java
protected void addBannerViewOverlap(String position, String size) { removeBannerViewOverlap();/* ww w . ja va 2 s . c o m*/ if (bannerViewLayout == null) { bannerViewLayout = new RelativeLayout(plugin.getCordova().getActivity());// RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); bannerViewLayout.setLayoutParams(params); ((ViewGroup) getView(plugin.getWebView())).addView(bannerViewLayout); params = new RelativeLayout.LayoutParams(AdView.LayoutParams.WRAP_CONTENT, AdView.LayoutParams.WRAP_CONTENT); if (position.equals("top-left")) { Log.d(LOG_TAG, "top-left"); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); } else if (position.equals("top-center")) { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } else if (position.equals("top-right")) { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else if (position.equals("left")) { params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("center")) { params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("right")) { params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("bottom-left")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); } else if (position.equals("bottom-center")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } else if (position.equals("bottom-right")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } bannerView.setLayoutParams(params); bannerViewLayout.addView(bannerView); } }
From source file:de.mrapp.android.dialog.decorator.MaterialDialogDecorator.java
/** * Creates and returns the layout params, which should be used by the dialog's root view. * * @return The layout params, which have been created, as an instance of the class {@link * RelativeLayout.LayoutParams}/*ww w.j a v a 2 s. co m*/ */ private RelativeLayout.LayoutParams createLayoutParams() { Rect windowDimensions = new Rect(); Window window = getWindow(); assert window != null; window.getDecorView().getWindowVisibleDisplayFrame(windowDimensions); int shadowWidth = isFullscreen() ? 0 : getContext().getResources().getDimensionPixelSize(R.dimen.dialog_shadow_width); int leftInset = isFitsSystemWindowsLeft() && isFullscreen() && windowInsets != null ? windowInsets.left : 0; int topInset = isFitsSystemWindowsTop() && isFullscreen() && windowInsets != null ? windowInsets.top : 0; int rightInset = isFitsSystemWindowsRight() && isFullscreen() && windowInsets != null ? windowInsets.right : 0; int bottomInset = isFitsSystemWindowsBottom() && isFullscreen() && windowInsets != null ? windowInsets.bottom : 0; int leftMargin = getLeftMargin() - shadowWidth + leftInset; int topMargin = getTopMargin() - shadowWidth + topInset; int rightMargin = getRightMargin() - shadowWidth + rightInset; int bottomMargin = getBottomMargin() - shadowWidth + bottomInset; int width = getLayoutDimension(getWidth(), leftMargin + rightMargin, windowDimensions.right); int height = getLayoutDimension(getHeight(), topMargin + bottomMargin, windowDimensions.bottom); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height); layoutParams.leftMargin = leftMargin; layoutParams.topMargin = topMargin; layoutParams.rightMargin = rightMargin; layoutParams.bottomMargin = bottomMargin; if ((getGravity() & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) { layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); } if ((getGravity() & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) { layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); } if ((getGravity() & Gravity.LEFT) == Gravity.LEFT) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); } if ((getGravity() & Gravity.TOP) == Gravity.TOP) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); } if ((getGravity() & Gravity.RIGHT) == Gravity.RIGHT) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); } if ((getGravity() & Gravity.BOTTOM) == Gravity.BOTTOM) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); } return layoutParams; }
From source file:com.example.damerap_ver1.IntroVideoActivity.java
/** * Create the view in which the video will be rendered. *///from w ww .j a v a 2s. co m private void setupView() { LinearLayout lLinLayout = new LinearLayout(this); lLinLayout.setId(1); lLinLayout.setOrientation(LinearLayout.VERTICAL); lLinLayout.setGravity(Gravity.CENTER); lLinLayout.setBackgroundColor(Color.BLACK); LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); lLinLayout.setLayoutParams(lLinLayoutParms); this.setContentView(lLinLayout); RelativeLayout lRelLayout = new RelativeLayout(this); lRelLayout.setId(2); lRelLayout.setGravity(Gravity.CENTER); lRelLayout.setBackgroundColor(Color.BLACK); android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); lRelLayout.setLayoutParams(lRelLayoutParms); lLinLayout.addView(lRelLayout); mVideoView = new VideoView(this); mVideoView.setId(3); android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); mVideoView.setLayoutParams(lVidViewLayoutParams); lRelLayout.addView(mVideoView); mProgressBar = new ProgressBar(this); mProgressBar.setId(4); android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT); mProgressBar.setLayoutParams(lProgressBarLayoutParms); lRelLayout.addView(mProgressBar); mProgressMessage = new TextView(this); mProgressMessage.setId(5); android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL); lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4); mProgressMessage.setLayoutParams(lProgressMsgLayoutParms); mProgressMessage.setTextColor(Color.LTGRAY); mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8); mProgressMessage.setText("..."); lRelLayout.addView(mProgressMessage); }
From source file:com.svpino.longhorn.fragments.StockListFragment.java
private void displayStockOverview(Integer position, boolean animate) { if (position != null) { setCurrentTile(position);/*from w w w. j a v a 2 s . c o m*/ setStockOverviewState(StockOverviewState.OVERVIEW); } displayStockInViewFlipper(position); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, Extensions.dpToPixels(getResources(), STOCK_OVERVIEW_HEIGHT)); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); this.viewFlipper.setLayoutParams(layoutParams); if (animate) { Animation animation = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.slide_in_from_bottom); animation.setAnimationListener( new StockOverviewAnimationListener(this.animateStockOverviewContentCallback)); this.viewFlipper.setVisibility(View.VISIBLE); this.viewFlipper.startAnimation(animation); } else { this.viewFlipper.setVisibility(View.VISIBLE); } collapseSearchActionView(); invalidateOptionsMenu(); }
From source file:org.odk.collect.android.views.MediaLayout.java
public void setAVT(FormIndex index, String selectionDesignator, TextView text, String audioURI, String imageURI, String videoURI, final String bigImageURI) { this.selectionDesignator = selectionDesignator; this.index = index; viewText = text;// w w w . j a v a 2s. co m originalText = text.getText(); viewText.setId(ViewIds.generateViewId()); this.videoURI = videoURI; // Layout configurations for our elements in the relative layout RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams audioParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams videoParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); // First set up the audio button if (audioURI != null) { // An audio file is specified audioButton = new AudioButton(getContext(), this.index, this.selectionDesignator, audioURI, player); audioButton.setPadding(22, 12, 22, 12); audioButton.setBackgroundColor(Color.LTGRAY); audioButton.setOnClickListener(this); audioButton.setId(ViewIds.generateViewId()); // random ID to be used by the // relative layout. } else { // No audio file specified, so ignore. } // Then set up the video button if (videoURI != null) { // An video file is specified videoButton = new AppCompatImageButton(getContext()); Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), android.R.drawable.ic_media_play); videoButton.setImageBitmap(b); videoButton.setPadding(22, 12, 22, 12); videoButton.setBackgroundColor(Color.LTGRAY); videoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "playVideoPrompt" + MediaLayout.this.selectionDesignator, MediaLayout.this.index); MediaLayout.this.playVideo(); } }); videoButton.setId(ViewIds.generateViewId()); } else { // No video file specified, so ignore. } // Now set up the image view String errorMsg = null; final int imageId = ViewIds.generateViewId(); if (imageURI != null) { try { String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI(); final File imageFile = new File(imageFilename); if (imageFile.exists()) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth); if (b != null) { imageView = new ImageView(getContext()); imageView.setPadding(2, 2, 2, 2); imageView.setImageBitmap(b); imageView.setId(imageId); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (bigImageURI != null) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick", "showImagePromptBigImage" + MediaLayout.this.selectionDesignator, MediaLayout.this.index); try { File bigImage = new File(ReferenceManager.instance() .DeriveReference(bigImageURI).getLocalURI()); Intent i = new Intent("android.intent.action.VIEW"); i.setDataAndType(Uri.fromFile(bigImage), "image/*"); getContext().startActivity(i); } catch (InvalidReferenceException e) { Timber.e(e, "Invalid image reference due to %s ", e.getMessage()); } catch (ActivityNotFoundException e) { Timber.d(e, "No Activity found to handle due to %s", e.getMessage()); ToastUtils.showShortToast( getContext().getString(R.string.activity_not_found, "view image")); } } else { if (viewText instanceof RadioButton) { ((RadioButton) viewText).setChecked(true); } else if (viewText instanceof CheckBox) { CheckBox checkbox = (CheckBox) viewText; checkbox.setChecked(!checkbox.isChecked()); } } } }); } else { // Loading the image failed, so it's likely a bad file. errorMsg = getContext().getString(R.string.file_invalid, imageFile); } } else { // We should have an image, but the file doesn't exist. errorMsg = getContext().getString(R.string.file_missing, imageFile); } if (errorMsg != null) { // errorMsg is only set when an error has occurred Timber.e(errorMsg); missingImage = new TextView(getContext()); missingImage.setText(errorMsg); missingImage.setPadding(10, 10, 10, 10); missingImage.setId(imageId); } } catch (InvalidReferenceException e) { Timber.e(e, "Invalid image reference due to %s ", e.getMessage()); } } else { // There's no imageURI listed, so just ignore it. } // e.g., for TextView that flag will be true boolean isNotAMultipleChoiceField = !RadioButton.class.isAssignableFrom(text.getClass()) && !CheckBox.class.isAssignableFrom(text.getClass()); // Determine the layout constraints... // Assumes LTR, TTB reading bias! if (viewText.getText().length() == 0 && (imageView != null || missingImage != null)) { // No text; has image. The image is treated as question/choice icon. // The Text view may just have a radio button or checkbox. It // needs to remain in the layout even though it is blank. // // The image view, as created above, will dynamically resize and // center itself. We want it to resize but left-align itself // in the resized area and we want a white background, as otherwise // it will show a grey bar to the right of the image icon. if (imageView != null) { imageView.setScaleType(ScaleType.FIT_START); } // // In this case, we have: // Text upper left; image upper, left edge aligned with text right edge; // audio upper right; video below audio on right. textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); if (isNotAMultipleChoiceField) { imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); } else { imageParams.addRule(RelativeLayout.RIGHT_OF, viewText.getId()); } imageParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); if (audioButton != null && videoButton == null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); audioParams.setMargins(0, 0, 11, 0); imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId()); } else if (audioButton == null && videoButton != null) { videoParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.setMargins(0, 0, 11, 0); imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId()); } else if (audioButton != null && videoButton != null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); audioParams.setMargins(0, 0, 11, 0); imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId()); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.addRule(RelativeLayout.BELOW, audioButton.getId()); videoParams.setMargins(0, 20, 11, 0); imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId()); } else { // the image will implicitly scale down to fit within parent... // no need to bound it by the width of the parent... if (!isNotAMultipleChoiceField) { imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } } imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } else { // We have a non-blank text label -- image is below the text. // In this case, we want the image to be centered... if (imageView != null) { imageView.setScaleType(ScaleType.FIT_START); } // // Text upper left; audio upper right; video below audio on right. // image below text, audio and video buttons; left-aligned with text. textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); if (audioButton != null && videoButton == null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); audioParams.setMargins(0, 0, 11, 0); textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId()); } else if (audioButton == null && videoButton != null) { videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.setMargins(0, 0, 11, 0); textParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId()); } else if (audioButton != null && videoButton != null) { audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); audioParams.setMargins(0, 0, 11, 0); textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId()); videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); videoParams.setMargins(0, 20, 11, 0); videoParams.addRule(RelativeLayout.BELOW, audioButton.getId()); } else { textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } if (imageView != null || missingImage != null) { imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); imageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); if (videoButton != null) { imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId()); } else if (audioButton != null) { imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId()); } imageParams.addRule(RelativeLayout.BELOW, viewText.getId()); } else { textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } } addView(viewText, textParams); if (audioButton != null) { addView(audioButton, audioParams); } if (videoButton != null) { addView(videoButton, videoParams); } if (imageView != null) { addView(imageView, imageParams); } else if (missingImage != null) { addView(missingImage, imageParams); } }
From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java
protected void addBannerViewOverlap(String position, String size) { if (bannerViewLayout == null) { bannerViewLayout = new RelativeLayout(plugin.getCordova().getActivity());// RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); bannerViewLayout.setLayoutParams(params); //plugin.getWebView().addView(bannerViewLayout, params); //plugin.getWebView().addView(bannerViewLayout);//only for ~cordova4 //((ViewGroup)plugin.getWebView().getRootView()).addView(bannerViewLayout);//only for ~cordova4 //((ViewGroup)plugin.getWebView().getView()).addView(bannerViewLayout);//only for cordova5~ ((ViewGroup) getView(plugin.getWebView())).addView(bannerViewLayout); }/*w w w . java2s. c o m*/ //http://tigerwoods.tistory.com/11 //http://developer.android.com/reference/android/widget/RelativeLayout.html //http://stackoverflow.com/questions/24900725/admob-banner-poitioning-in-android-on-bottom-of-the-screen-using-no-xml-relative RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(AdView.LayoutParams.WRAP_CONTENT, AdView.LayoutParams.WRAP_CONTENT); if (position.equals("top-left")) { Log.d(LOG_TAG, "top-left"); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); } else if (position.equals("top-center")) { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } else if (position.equals("top-right")) { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else if (position.equals("left")) { params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("center")) { params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("right")) { params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.CENTER_VERTICAL); } else if (position.equals("bottom-left")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); } else if (position.equals("bottom-center")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } else if (position.equals("bottom-right")) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.CENTER_HORIZONTAL); } //bannerViewLayout.addView(bannerView, params); bannerView.setLayoutParams(params); bannerViewLayout.addView(bannerView); }