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:org.zywx.wbpalmstar.engine.universalex.EUExBase.java
protected final void adptLayoutParams(RelativeLayout.LayoutParams rParms, FrameLayout.LayoutParams outParm) { if (null == rParms) { return;/*from www .jav a2s.c om*/ } int TRUE = RelativeLayout.TRUE; int ALIGN_PARENT_LEFT = RelativeLayout.ALIGN_PARENT_LEFT; int ALIGN_PARENT_TOP = RelativeLayout.ALIGN_PARENT_TOP; int ALIGN_PARENT_RIGHT = RelativeLayout.ALIGN_PARENT_RIGHT; int ALIGN_PARENT_BOTTOM = RelativeLayout.ALIGN_PARENT_BOTTOM; int CENTER_IN_PARENT = RelativeLayout.CENTER_IN_PARENT; int CENTER_HORIZONTAL = RelativeLayout.CENTER_HORIZONTAL; int CENTER_VERTICAL = RelativeLayout.CENTER_VERTICAL; try { int[] rules = rParms.getRules(); if (rules[ALIGN_PARENT_LEFT] == TRUE) { outParm.gravity |= Gravity.LEFT; } if (rules[ALIGN_PARENT_TOP] == TRUE) { outParm.gravity |= Gravity.TOP; } if (rules[ALIGN_PARENT_RIGHT] == TRUE) { outParm.gravity |= Gravity.RIGHT; } if (rules[ALIGN_PARENT_BOTTOM] == TRUE) { outParm.gravity |= Gravity.BOTTOM; } if (rules[CENTER_IN_PARENT] == TRUE) { outParm.gravity |= Gravity.CENTER; } if (rules[CENTER_HORIZONTAL] == TRUE) { outParm.gravity |= Gravity.CENTER_HORIZONTAL; } if (rules[CENTER_VERTICAL] == TRUE) { outParm.gravity |= Gravity.CENTER_VERTICAL; } } catch (Exception e) { ; } }
From source file:com.android.contacts.group.GroupMembersFragment.java
@Override protected View inflateView(LayoutInflater inflater, ViewGroup container) { final View view = inflater.inflate(R.layout.contact_list_content, /* root */ null); final View emptyGroupView = inflater.inflate(R.layout.empty_group_view, null); final ImageView image = (ImageView) emptyGroupView.findViewById(R.id.empty_group_image); final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) image.getLayoutParams(); final int screenHeight = getResources().getDisplayMetrics().heightPixels; params.setMargins(0,// ww w. j a v a2 s .c o m screenHeight / getResources().getInteger(R.integer.empty_group_view_image_margin_divisor), 0, 0); params.gravity = Gravity.CENTER_HORIZONTAL; image.setLayoutParams(params); final FrameLayout contactListLayout = (FrameLayout) view.findViewById(R.id.contact_list); contactListLayout.addView(emptyGroupView); final Button addContactsButton = (Button) emptyGroupView.findViewById(R.id.add_member_button); addContactsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivityForResult( GroupUtil.createPickMemberIntent(getContext(), mGroupMetaData, getMemberContactIds()), RESULT_GROUP_ADD_MEMBER); } }); return view; }
From source file:com.abc.driver.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (menu_display) { menuWindow.dismiss();//from w w w . j a v a 2 s .c o m menu_display = false; } else { onBackPressed(); } } else if (keyCode == KeyEvent.KEYCODE_MENU) { if (!menu_display) { inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); layout = inflater.inflate(R.layout.main_menu, null); menuWindow = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); menuWindow.showAtLocation(this.findViewById(R.id.mainweixin), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); mClose = (LinearLayout) layout.findViewById(R.id.menu_close); mCloseBtn = (LinearLayout) layout.findViewById(R.id.menu_close_btn); mCloseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(); menuWindow.dismiss(); } }); menu_display = true; } else { menuWindow.dismiss(); menu_display = false; } return false; } return false; }
From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceTile.java
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.tile_status_wireless_iface_qrcode: if (wifiEncryptionType == null || (isNullOrEmpty(wifiSsid) && isNullOrEmpty(wifiPassword))) { //menu item should have been disabled, but anyways, you never know :) Toast.makeText(mParentFragmentActivity, "Missing parameters to generate QR-Code - try again later", Toast.LENGTH_SHORT).show(); return true; }//from w ww . j ava 2s .c o m //https://github.com/zxing/zxing/wiki/Barcode-Contents //noinspection ConstantConditions final String wifiSsidNullToEmpty = nullToEmpty(wifiSsid); final String wifiQrCodeString = String.format("WIFI:S:%s;T:%s;P:%s;%s;", escapeString(wifiSsidNullToEmpty), wifiEncryptionType.toString(), escapeString(nullToEmpty(wifiPassword)), wifiSsidNullToEmpty.isEmpty() ? "H:true" : ""); final String routerUuid = mRouter.getUuid(); final Class<?> activityClass = Utils.isThemeLight(mParentFragmentActivity, routerUuid) ? WirelessIfaceQrCodeActivityLight.class : WirelessIfaceQrCodeActivity.class; final Intent intent = new Intent(mParentFragmentActivity, activityClass); intent.putExtra(RouterManagementActivity.ROUTER_SELECTED, routerUuid); intent.putExtra(WirelessIfaceQrCodeActivity.SSID, wifiSsidNullToEmpty); intent.putExtra(WirelessIfaceQrCodeActivity.WIFI_QR_CODE, wifiQrCodeString); final AlertDialog alertDialog = Utils.buildAlertDialog(mParentFragmentActivity, null, String.format("Generating QR Code for '%s'", wifiSsidNullToEmpty), false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { mParentFragmentActivity.startActivity(intent); alertDialog.cancel(); } }, 2500); return true; default: break; } return false; }
From source file:com.cpic.taylor.logistics.activity.HomeActivity.java
/** * /*from ww w . j av a 2 s . c o m*/ * @param v * @param type1 * @param type2 * @param isUser */ private void showPopupWindow(View v, final int type1, final int type2, final boolean isUser) { View view = View.inflate(HomeActivity.this, R.layout.popupwindow_1, null); tvCamera = (TextView) view.findViewById(R.id.btn_camera); tvPhoto = (TextView) view.findViewById(R.id.btn_photo); tvBack = (TextView) view.findViewById(R.id.btn_back); tvCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFromCamera(type1, isUser); pw.dismiss(); } }); tvPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFromPhoto(type2); pw.dismiss(); } }); tvBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); } }); pw = new PopupWindow(view, screenWidth * 99 / 100, LinearLayout.LayoutParams.WRAP_CONTENT); pw.setFocusable(true); WindowManager.LayoutParams params = HomeActivity.this.getWindow().getAttributes(); HomeActivity.this.getWindow().setAttributes(params); pw.setBackgroundDrawable(new ColorDrawable()); pw.setOutsideTouchable(true); pw.setAnimationStyle(R.style.pw_anim_style); pw.showAtLocation(v, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); pw.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { WindowManager.LayoutParams params = HomeActivity.this.getWindow().getAttributes(); params.alpha = 1f; HomeActivity.this.getWindow().setAttributes(params); } }); }
From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java
private void finishDismiss(View dismissView, int originalLayoutHeight) { // Make sure no other animation is running. Remove animation from running list, that just finished boolean noAnimationLeft; synchronized (mAnimationLock) { --mDismissAnimationRefCount;/*from w ww . j a v a 2s . c o m*/ mAnimatedViews.remove(dismissView); noAnimationLeft = mDismissAnimationRefCount == 0; } if (noAnimationLeft) { // No active animations, process all pending dismisses. for (PendingDismissData dismiss : mPendingDismisses) { if (mUndoStyle == UndoStyle.SINGLE_POPUP) { for (Undoable undoable : mUndoActions) { undoable.discard(); } mUndoActions.clear(); } Undoable undoable = mCallbacks.onDismiss(dismiss.position); if (undoable != null) { mUndoActions.add(undoable); } mValidDelayedMsgId++; } if (!mUndoActions.isEmpty()) { changePopupText(); changeButtonLabel(); // Show undo popup float yLocationOffset = mListView.getResources().getDimension(R.dimen.undo_bottom_offset); mUndoPopup.setWidth((int) Math.min(mScreenDensity * 400, mListView.getWidth() * 0.9f)); mUndoPopup.showAtLocation(mListView, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, (int) yLocationOffset); // Queue the dismiss only if required if (!mTouchBeforeAutoHide) { // Send a delayed message to hide popup mHideUndoHandler.sendMessageDelayed(mHideUndoHandler.obtainMessage(mValidDelayedMsgId), mUndoHideDelay); } } ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { ViewCompat.setAlpha(pendingDismiss.view, 1f); ViewCompat.setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.childView.getLayoutParams(); lp.height = originalLayoutHeight; pendingDismiss.childView.setLayoutParams(lp); } mPendingDismisses.clear(); } }
From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java
private void createTableLayoutTrainAvailability() { if (mPage.contains("SORRY")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Not a valid class, Please select a different class and try again."); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews();// w ww . j a va2 s.co m mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ISL Of")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ERROR")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("Network Connectivity")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("unavailable")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText( "Response from server:\n\nYour request could not be processed now.\nPlease try again later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) { Iterator iterator = null; try { iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("TrainDetails", mPage); e.printStackTrace(); return; } mListAv = new ArrayList<List<String>>(); List<String> list; Element tmp; tmp = (Element) iterator.next(); list = new ArrayList<String>(); list.add(tmp.select("th").get(0).text()); list.add("Date"); list.add(tmp.select("th").get(2).text()); //list.add(tmp.select("th").get(3).text()); mListAv.add(list); while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (!tmp.hasText()) { continue; } list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); //list.add(tmp.select("td").get(3).text()); mListAv.add(list); } mDetails = new Details(mListAv, TrainEnquiry.AVAILABILITY, mTrainNumber); } else { mListAv = mDetails.getList(); } mTblLayoutAv = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3; mTblLayoutAv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < mListAv.size(); i++) { row = new TableRow(mActivity); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); //tv4 = new TextView(mActivity); tv1.setText(" " + mListAv.get(i).get(0)); tv2.setText(" " + mListAv.get(i).get(1)); tv3.setText(" " + mListAv.get(i).get(2)); //tv4.setText(" " + mListAv.get(i).get(3)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); //tv4.setTextAppearance(mActivity,android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(5, 5, 5, 5); tv2.setPadding(5, 5, 5, 5); tv3.setPadding(5, 5, 5, 5); //tv4.setPadding(5,5,5,5); /*tv2.setBackgroundResource(R.drawable.card_divider); tv3.setBackgroundResource(R.drawable.card_divider); tv4.setBackgroundResource(R.drawable.card_divider);*/ row.addView(tv1); row.addView(tv2); row.addView(tv3); //row.addView(tv4); row.setBackgroundResource(R.drawable.button_selector); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); row.setOnClickListener(this); mTblLayoutAv.addView(row); } LinearLayout ll = new LinearLayout(mActivity); ScrollView scrollView = new ScrollView(mActivity); TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Availability details:"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(mTblLayoutAv); scrollView.addView(ll); mFrameLayout.removeAllViews(); mFrameLayout.addView(scrollView); if (mDialog.isShowing()) { mDialog.cancel(); } }
From source file:com.hotstar.player.adplayer.player.PlayerFragment.java
/** * Set the player view size with givent width and height * //from w ww . j a va2 s . co m * @param movieWidth * the width of the player view to be set to * @param movieHeight * the height of the player view to be set to */ private void setPlayerViewSize(long movieWidth, long movieHeight) { if (mediaPlayer == null || mediaPlayer.getView() == null) { AdVideoApplication.logger.w(LOG_TAG + "#setPlayerViewSize", "Unable to find player view."); return; } AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Original movie size: " + movieWidth + "x" + movieHeight); FrameLayout layout = (FrameLayout) playerFragmentView.findViewById(R.id.playerFrame); int layoutWidth = layout.getWidth(); int layoutHeight = layout.getHeight(); float screenAspectRatio = (float) layoutWidth / layoutHeight; if (movieWidth == 0 || movieHeight == 0) { // If movie size is not available, fill the screen. movieWidth = layoutWidth; movieHeight = layoutHeight; } float movieAspectRatio = (float) movieWidth / movieHeight; int width, height; if (movieAspectRatio <= screenAspectRatio) { // Resize to fill height. width = (int) (layoutHeight * movieAspectRatio); height = layoutHeight; } else { // Resize to fill width. width = layoutWidth; height = (int) (layoutWidth * (1 / movieAspectRatio)); } AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Movie width x height: " + movieWidth + "x" + movieHeight); AdVideoApplication.logger.i(LOG_TAG + "#setPlayerViewSize", "Setting player view size to: " + width + "x" + height); mediaPlayer.getView().setLayoutParams( new FrameLayout.LayoutParams(width, height, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL)); RelativeLayout overlayAdLayout = (RelativeLayout) playerFragmentView.findViewById(R.id.OverlayAdLayout); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height); layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 1); layoutParams.addRule(RelativeLayout.ABOVE, controlBar.getView().getId()); overlayAdLayout.setLayoutParams(layoutParams); }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w. j a v a 2s .c o m*/ 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 { // Drawer, if it wasn't onMeasure would have thrown an // exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight; } else { // Right; onMeasure checked for us. childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - 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: { final int width = r - l; child.layout(width - lp.rightMargin - childWidth, childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { final int width = r - l; int childLeft = (width - childWidth) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. 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:com.google.fpl.voltair.VoltAirActivity.java
private void showAchievementToast(final String prefix, final String achievementName) { runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(VoltAirActivity.this, String.format("%s: %s", prefix, getAchievementTitle(achievementName)), Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show();/* ww w.j a v a2 s. c o m*/ } }); }