List of usage examples for android.view Gravity CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.view Gravity CENTER_HORIZONTAL.
Click Source Link
From source file:xj.property.activity.HXBaseActivity.HXBaseActivity.java
protected void showMiddleToast(String str) { showCommonToast(str, Gravity.CENTER | Gravity.CENTER_HORIZONTAL); }
From source file:xj.property.activity.HXBaseActivity.HXBaseActivity.java
protected void showTopToast(String str) { showCommonToast(str, Gravity.TOP | Gravity.CENTER_HORIZONTAL); }
From source file:xj.property.activity.HXBaseActivity.HXBaseActivity.java
protected void showButtomToast(String str) { showCommonToast(str, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); }
From source file:org.otempo.view.StationActivity.java
/** * Actualiza la parte del layout que visualiza predicciones *//* w w w. j a v a2 s .c o m*/ private void updateLayout() { final LinearLayout scrolled = findViewById(R.id.scrolled); scrolled.removeAllViews(); final LinearLayout predictedGroup = findViewById(R.id.predictedGroup); if (predictedGroup != null) { // en landscape no hay predictedGroup.setVisibility(LinearLayout.INVISIBLE); } final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutUtils.dips(75, this), LinearLayout.LayoutParams.WRAP_CONTENT); Station currentStation = _stationManager.getStation(); if (currentStation == null) { // Si no hay estacin elegida, nada ms que hacer... return; } final int currentStationId = currentStation.getId(); if (currentStation.getPredictions().size() > 0) { removeDialog(DIALOG_LOADING_ID); if (predictedGroup != null) { // en landscape no hay final TextView predictionTime = findViewById(R.id.predictionTime); predictionTime.setText(getPredictionTimeString(currentStation.getLastCreationDate())); predictedGroup.setVisibility(LinearLayout.VISIBLE); } currentStation.acceptPredictionVisitor(new StationPredictionVisitor() { @Override public void apply(@NonNull StationShortTermPrediction shortPred, final int index) { Calendar predictionDate = shortPred.getDate(); if (predictionDate == null || !DateUtils.isFromToday(predictionDate)) { return; } LinearLayout day = new LinearLayout(StationActivity.this); day.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { showDialog(DIALOG_DAY_COMMENT_MASK + index + currentStationId * MAX_PREDICTED_DAYS); } }); day.setOrientation(LinearLayout.VERTICAL); TextView dayName = getDayName(shortPred.getDate()); day.addView(dayName); ImageView morningIcon = new ImageView(StationActivity.this); morningIcon.setImageResource(ResourceUtils.getResource(shortPred.getSkyStateMorning(), true)); day.addView(morningIcon); ImageView afternoonIcon = new ImageView(StationActivity.this); afternoonIcon .setImageResource(ResourceUtils.getResource(shortPred.getSkyStateAfternoon(), true)); day.addView(afternoonIcon); ImageView nightIcon = new ImageView(StationActivity.this); nightIcon.setImageResource(ResourceUtils.getResource(shortPred.getSkyStateNight(), false)); day.addView(nightIcon); TextView temps = new TextView(StationActivity.this); temps.setText(shortPred.getMinTemp() + " - " + shortPred.getMaxTemp() + " C"); temps.setGravity(Gravity.CENTER_HORIZONTAL); day.addView(temps); if (DateUtils.isToday(predictionDate)) { day.setBackgroundResource(R.drawable.today_bg); temps.setTypeface(Typeface.DEFAULT, Typeface.BOLD); dayName.setTypeface(Typeface.DEFAULT, Typeface.BOLD); } scrolled.addView(day, params); } @Override public void apply(@NonNull StationMediumTermPrediction medPred, final int index) { Calendar predictionDate = medPred.getDate(); if (predictionDate == null || !DateUtils.isFromToday(predictionDate)) { return; } LinearLayout day = new LinearLayout(StationActivity.this); day.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { showDialog(DIALOG_DAY_COMMENT_MASK + index + currentStationId * MAX_PREDICTED_DAYS); } }); day.setOrientation(LinearLayout.VERTICAL); TextView dayName = getDayName(medPred.getDate()); day.addView(dayName); ImageView morningIcon = new ImageView(StationActivity.this); morningIcon.setImageResource(ResourceUtils.getResource(medPred.getSkyState(), true)); day.addView(morningIcon); TextView temps = new TextView(StationActivity.this); temps.setText(medPred.getMinTemp() + " - " + medPred.getMaxTemp() + " C"); temps.setGravity(Gravity.CENTER_HORIZONTAL); temps.setTextColor(Color.WHITE); day.addView(temps); scrolled.addView(day, params); } }); } else { // Ahora mostramos el dilogo si hace falta, y sino borramos la marca de skip if (_skipDialog) { _skipDialog = false; } else { if (!this.isFinishing()) { showDialog(DIALOG_LOADING_ID); fetchThenShow(currentStation, false); } } } }
From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java
private void showOfflinePNRStatus(String trainDetails, ArrayList<String> passnDetails) { LinearLayout ll = new LinearLayout(mActivity); TextView textViewTrnDtls = new TextView(mActivity); TextView textViewPsnDtls = new TextView(mActivity); TextView tvTrainDetails = new TextView(mActivity); TextView[] tvPassnDetails = new TextView[passnDetails.size()]; textViewTrnDtls.setText("Train Details: " + mPNRNumber); textViewTrnDtls.setFocusable(true);//w w w. j a va2 s .com textViewPsnDtls.setText("Passenger Details"); tvTrainDetails.setText(trainDetails); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); tvTrainDetails.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewPsnDtls.setPadding(10, 10, 10, 10); tvTrainDetails.setPadding(10, 10, 10, 10); tvTrainDetails.setBackgroundResource(R.drawable.card_background); textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(tvTrainDetails); ll.addView(textViewPsnDtls); for (int i = 0; i < passnDetails.size(); ++i) { tvPassnDetails[i] = new TextView(mActivity); tvPassnDetails[i].setText(passnDetails.get(i)); tvPassnDetails[i].setPadding(10, 10, 10, 10); tvPassnDetails[i].setBackgroundResource(R.drawable.card_background); tvPassnDetails[i].setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); ll.addView(tvPassnDetails[i]); } mFrameLayout.removeAllViews(); mFrameLayout.addView(ll); }
From source file:com.facebook.LikeView.java
private void updateLayout() { // Make sure the container is horizontally aligned according to specifications. LayoutParams containerViewLayoutParams = (LayoutParams) containerView.getLayoutParams(); LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) likeButton.getLayoutParams(); int viewGravity = horizontalAlignment == HorizontalAlignment.LEFT ? Gravity.LEFT : horizontalAlignment == HorizontalAlignment.CENTER ? Gravity.CENTER_HORIZONTAL : Gravity.RIGHT; containerViewLayoutParams.gravity = viewGravity | Gravity.TOP; buttonLayoutParams.gravity = viewGravity; // Choose the right auxiliary view to make visible. socialSentenceView.setVisibility(GONE); likeBoxCountView.setVisibility(GONE); View auxView;/* w w w.java 2 s. co m*/ if (likeViewStyle == Style.STANDARD && likeActionController != null && !Utility.isNullOrEmpty(likeActionController.getSocialSentence())) { auxView = socialSentenceView; } else if (likeViewStyle == Style.BOX_COUNT && likeActionController != null && !Utility.isNullOrEmpty(likeActionController.getLikeCountString())) { updateBoxCountCaretPosition(); auxView = likeBoxCountView; } else { // No more work to be done. return; } auxView.setVisibility(VISIBLE); // Now position the auxiliary view properly LinearLayout.LayoutParams auxViewLayoutParams = (LinearLayout.LayoutParams) auxView.getLayoutParams(); auxViewLayoutParams.gravity = viewGravity; containerView.setOrientation(auxiliaryViewPosition == AuxiliaryViewPosition.INLINE ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); if (auxiliaryViewPosition == AuxiliaryViewPosition.TOP || (auxiliaryViewPosition == AuxiliaryViewPosition.INLINE && horizontalAlignment == HorizontalAlignment.RIGHT)) { // Button comes after the auxiliary view. Make sure it is at the end containerView.removeView(likeButton); containerView.addView(likeButton); } else { // In all other cases, the button comes first containerView.removeView(auxView); containerView.addView(auxView); } switch (auxiliaryViewPosition) { case TOP: auxView.setPadding(edgePadding, edgePadding, edgePadding, internalPadding); break; case BOTTOM: auxView.setPadding(edgePadding, internalPadding, edgePadding, edgePadding); break; case INLINE: if (horizontalAlignment == HorizontalAlignment.RIGHT) { auxView.setPadding(edgePadding, edgePadding, internalPadding, edgePadding); } else { auxView.setPadding(internalPadding, edgePadding, edgePadding, edgePadding); } break; } }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addYoutubeVideo(String url) { final String yturl; if (url.contains("embed")) { String temp = url.split("embed/")[1]; if (url.contains("feature")) { temp = temp.split("feature=")[0]; yturl = temp.substring(0, temp.length() - 1); } else// w w w. ja v a2s.c o m yturl = temp; } else if (url.contains("youtu.be")) { yturl = url.split("youtu.be/")[1]; } else return; final RelativeLayout rl = new RelativeLayout(getActivity()); YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity()); ImageView icon = new ImageView(getActivity()); try { yt.setTag(yturl); yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() { @Override public void onInitializationFailure(YouTubeThumbnailView thumbView, YouTubeInitializationResult error) { rl.setVisibility(View.GONE); } @Override public void onInitializationSuccess(YouTubeThumbnailView thumbView, YouTubeThumbnailLoader thumbLoader) { thumbLoader.setVideo(yturl); } }); } catch (Exception e) { e.printStackTrace(); } RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL); obj_params.addRule(RelativeLayout.CENTER_VERTICAL); yt.setLayoutParams(obj_params); icon.setImageResource(R.drawable.yt_play_button); icon.setLayoutParams(obj_params); RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rl_params.setMargins(0, 10, 0, 0); rl.setLayoutParams(rl_params); rl.setGravity(Gravity.CENTER_HORIZONTAL); rl.setClickable(true); rl.addView(yt); rl.addView(icon); rl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), YoutubeActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra(Constants.KEY_VIDEO_URL, yturl); startActivity(i); } }); lay.addView(rl); }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void calculateUsingTextSize(final float textSize) { if (mText == null) return;//w w w . jav a2 s.c om final float availableWidth; final float newTextSize; boolean updateDrawText = false; // BEGIN MODIFICATION: Add maxLines variable int maxLines; // END MODIFICATION if (isClose(textSize, mCollapsedTextSize)) { availableWidth = mCollapsedBounds.width(); newTextSize = mCollapsedTextSize; mScale = 1f; if (mCurrentTypeface != mCollapsedTypeface) { mCurrentTypeface = mCollapsedTypeface; updateDrawText = true; } // BEGIN MODIFICATION: Set maxLines variable maxLines = 1; // END MODIFICATION } else { availableWidth = mExpandedBounds.width(); newTextSize = mExpandedTextSize; if (mCurrentTypeface != mExpandedTypeface) { mCurrentTypeface = mExpandedTypeface; updateDrawText = true; } if (isClose(textSize, mExpandedTextSize)) { // If we're close to the expanded text size, snap to it and use a scale of 1 mScale = 1f; } else { // Else, we'll scale down from the expanded text size mScale = textSize / mExpandedTextSize; } // BEGIN MODIFICATION: Set maxLines variable maxLines = this.maxLines; // END MODIFICATION } if (availableWidth > 0) { updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText; mCurrentTextSize = newTextSize; mBoundsChanged = false; } if (mTextToDraw == null || updateDrawText) { mTextPaint.setTextSize(mCurrentTextSize); mTextPaint.setTypeface(mCurrentTypeface); // BEGIN MODIFICATION: Text layout creation and text truncation StaticLayout layout = new StaticLayout(mText, mTextPaint, (int) availableWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0, false); CharSequence truncatedText; if (layout.getLineCount() > maxLines) { int lastLine = maxLines - 1; CharSequence textBefore = lastLine > 0 ? mText.subSequence(0, layout.getLineEnd(lastLine - 1)) : ""; CharSequence lineText = mText.subSequence(layout.getLineStart(lastLine), layout.getLineEnd(lastLine)); // if last char in line is space, move it behind the ellipsis CharSequence lineEnd = ""; if (lineText.charAt(lineText.length() - 1) == ' ') { lineEnd = lineText.subSequence(lineText.length() - 1, lineText.length()); lineText = lineText.subSequence(0, lineText.length() - 1); } // insert ellipsis character lineText = TextUtils.concat(lineText, "\u2026", lineEnd); // if the text is too long, truncate it CharSequence truncatedLineText = TextUtils.ellipsize(lineText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); truncatedText = TextUtils.concat(textBefore, truncatedLineText); } else { truncatedText = mText; } if (!TextUtils.equals(truncatedText, mTextToDraw)) { mTextToDraw = truncatedText; mIsRtl = calculateIsRtl(mTextToDraw); } final Layout.Alignment alignment; // Don't rectify gravity for RTL languages, Layout.Alignment does it already. switch (mExpandedTextGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: alignment = Layout.Alignment.ALIGN_CENTER; break; case Gravity.RIGHT: case Gravity.END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.LEFT: case Gravity.START: default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } mTextLayout = new StaticLayout(mTextToDraw, mTextPaint, (int) availableWidth, alignment, 1, 0, false); // END MODIFICATION } }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout()"); mInLayout = true;//from w ww . j av a2s. c om final int width = r - l; final int height = b - t; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childWidth; } else { childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { child.layout(width - lp.rightMargin, childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { int childLeft = (width - childWidth) / 2; if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static int getGravity(final String align, final boolean vertical) { if (align != null) { if ("left".equals(align)) { return Gravity.LEFT; } else if ("center".equals(align)) { return vertical ? Gravity.CENTER_VERTICAL : Gravity.CENTER_HORIZONTAL; } else if ("right".equals(align)) { return Gravity.RIGHT; } else if ("top".equals(align)) { return Gravity.TOP; } else if ("bottom".equals(align)) { return Gravity.BOTTOM; }//from ww w .jav a 2s . c o m } return Gravity.NO_GRAVITY; }