List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w ww . j av a 2 s. co m final int width = r - l; 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)) { try { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } catch (Exception e) { } } else { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } 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.nadmm.airports.ActivityBase.java
protected void setContentMsg(String msg) { TextView tv = new TextView(this); tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tv.setPadding(dpToPx(12), dpToPx(8), dpToPx(12), dpToPx(8)); tv.setText(msg);//from w w w . j a v a2 s . co m setContentView(createContentView(tv)); }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;//from ww w .j a va 2s. com final int width = r - l; 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 childLeft; final float newOffset; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } 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 void setAlignment(final TextView tv, final String textAlign, final String verticalAlign) { int gravity = Gravity.NO_GRAVITY; if (textAlign != null) { if ("left".equals(textAlign)) { gravity |= Gravity.LEFT;//from ww w.j av a 2 s. c om } else if ("center".equals(textAlign) || "middle".equals(textAlign)) { gravity |= Gravity.CENTER_HORIZONTAL; } else if ("right".equals(textAlign)) { gravity |= Gravity.RIGHT; } else { Log.w(TAG, "Unsupported horizontal alignment: " + textAlign); } } else { // Nothing has been set - let's set if something was set previously // You can do this with shortcut syntax - but long term maint of code is easier if it's explicit // Log.w(TAG, // "No alignment set - old horizontal align was: " + (tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK), // Log.DEBUG_MODE); if ((tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK) != Gravity.NO_GRAVITY) { // Something was set before - so let's use it gravity |= tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK; } } if (verticalAlign != null) { if ("top".equals(verticalAlign)) { gravity |= Gravity.TOP; } else if ("middle".equals(verticalAlign) || "center".equals(verticalAlign)) { gravity |= Gravity.CENTER_VERTICAL; } else if ("bottom".equals(verticalAlign)) { gravity |= Gravity.BOTTOM; } else { Log.w(TAG, "Unsupported vertical alignment: " + verticalAlign); } } else { // Nothing has been set - let's set if something was set previously // You can do this with shortcut syntax - but long term maint of code is easier if it's explicit // Log.w(TAG, "No alignment set - old vertical align was: " + (tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK), // Log.DEBUG_MODE); if ((tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK) != Gravity.NO_GRAVITY) { // Something was set before - so let's use it gravity |= tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK; } } tv.setGravity(gravity); }
From source file:com.retroteam.studio.retrostudio.EditorLandscape.java
/** * Create all the views associated with a track. * @param waveDrawableID//w w w .j av a 2 s .c o m * @param projectLoad * @return */ private ImageView addTrack(int waveDrawableID, boolean projectLoad) { //add the track with the measure adder to the view //get layout LinearLayout track_layout = (LinearLayout) findViewById(R.id.track_layout); //create track container HorizontalScrollView track_container = new HorizontalScrollView(getApplicationContext()); track_container.setLayoutParams(new HorizontalScrollView.LayoutParams( HorizontalScrollView.LayoutParams.MATCH_PARENT, displaysize.y / 4)); track_container.setBackground(getResources().getDrawable(R.color.track_container_bg)); //create grid layout GridLayout track_grid = new GridLayout(getApplicationContext()); track_grid.setColumnCount(100); track_grid.setRowCount(1); track_grid.setOrientation(GridLayout.HORIZONTAL); track_grid.setId(R.id.track_grid); //create linear layout for track id and wave LinearLayout track_identifier = new LinearLayout(getApplicationContext()); track_identifier.setLayoutParams(new LinearLayout.LayoutParams(displaysize.x / 14, displaysize.y / 4)); track_identifier.setOrientation(LinearLayout.VERTICAL); track_identifier.setBackgroundColor(getResources().getColor(R.color.black_overlay)); //create textview for linear layout TextView track_num = new TextView(getApplicationContext()); track_num.setText("1"); track_num.setTextSize(45); track_num.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL); //create imageview for linear layout ImageView track_type = new ImageView(getApplicationContext()); track_type.setImageResource(waveDrawableID); track_type.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); //create "add measure" for grid layout ImageView add_measure = new ImageView(getApplicationContext()); add_measure.setImageResource(R.drawable.measure_new); add_measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32), LinearLayout.LayoutParams.MATCH_PARENT)); if (projectLoad) { add_measure.setTag(R.id.TAG_ROW, trackReloadCounter); add_measure.setId(trackReloadCounter + 4200); } else { add_measure.setTag(R.id.TAG_ROW, theproject.size() - 1); add_measure.setId(theproject.size() - 1 + 4200); } add_measure.setTag(R.id.TAG_COLUMN, 0); add_measure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addMeasure(v, false); } }); track_identifier.addView(track_num); if (projectLoad) { track_num.setText(Integer.toString(trackReloadCounter + 1)); trackReloadCounter += 1; } else { track_num.setText(Integer.toString(theproject.size())); } track_num.setTextSize(45); track_identifier.addView(track_type); track_grid.addView(track_identifier); track_grid.addView(add_measure); track_container.addView(track_grid); track_layout.addView(track_container); return add_measure; }
From source file:com.popofibo.weatherpop.custom.DrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from www.j a v a 2 s . co m*/ final int width = r - l; 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 childLeft; final float newOffset; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } 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.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
private static int parseGravity(String value) { int gravity = Gravity.NO_GRAVITY; String[] parts = value.toLowerCase().split("[|]"); for (String part : parts) { switch (part) { case "center": gravity = gravity | Gravity.CENTER; break; case "left": case "textStart": gravity = gravity | Gravity.LEFT; break; case "right": case "textEnd": gravity = gravity | Gravity.RIGHT; break; case "top": gravity = gravity | Gravity.TOP; break; case "bottom": gravity = gravity | Gravity.BOTTOM; break; case "center_horizontal": gravity = gravity | Gravity.CENTER_HORIZONTAL; break; case "center_vertical": gravity = gravity | Gravity.CENTER_VERTICAL; break; }/* w ww . j a va 2 s . co m*/ } return gravity; }
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
private void displayArtistInfo_bk(JSONObject j) throws JSONException { if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config);//from www . j a v a2 s . c om Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString()); JSONObject j_artist_info = j.getJSONObject("artist"); tArtistName.setText(j_artist_info.getString("name")); final JSONObject urls = j_artist_info.optJSONObject("urls"); final JSONArray videos = j_artist_info.optJSONArray("video"); final JSONArray images = j_artist_info.optJSONArray("images"); final String fm_image = j.optString("fm_image"); final JSONArray available_images = new JSONArray(); ArrayList<String> image_urls = new ArrayList<String>(); if (fm_image != null) { image_urls.add(fm_image); } Log.i("musicInfo", images.toString()); if (images != null) { for (int i = 0; i < images.length(); i++) { JSONObject image = images.getJSONObject(i); int width = image.optInt("width", 0); int height = image.optInt("height", 0); String url = image.optString("url", ""); Log.i("musicInfo", i + ": " + url); if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) { //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) { image_urls.add(url); Log.i("musicInfo", "Selected: " + url); //available_images.put(image); } } int random = (int) (Math.random() * image_urls.size()); final String f_url = image_urls.get(random); //int random = (int) (Math.random() * available_images.length()); //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0); Log.i("musicInfo", "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url); imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { lLinkList.removeAllViews(); //String attr = fImage.optJSONObject("license").optString("attribution"); //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr)); if (urls != null) { String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url", "twitter_url" }; for (int i = 0; i < jsonName.length; i++) { if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) { Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i])); TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); switch (jsonName[i]) { case "official_url": tv.setText("HOME."); break; case "wikipedia_url": tv.setText("WIKI."); break; case "mb_url": tv.setText("Music Brainz."); break; case "lastfm_url": tv.setText("Last FM."); break; case "twitter_url": tv.setText("Twitter."); break; } try { tv.setTag(urls.getString(jsonName[i])); } catch (JSONException e) { e.printStackTrace(); } tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse((String) v.getTag())); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); Toast.makeText(getApplicationContext(), "Open the Link...", Toast.LENGTH_SHORT).show(); //finish(); } }); lLinkList.addView(tv); } } } else { TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setText("Sorry, No Link Here..."); lLinkList.addView(tv); } if (videos != null) { jVideoArray = videos; mAdapter = new StaggeredViewAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, generateImageData(videos)); //if (mData == null) { mData = generateImageData(videos); //} //mAdapter.clear(); for (JSONObject data : mData) { mAdapter.add(data); } mGridView.setAdapter(mAdapter); } else { } adjBottomColor(((ImageView) view).getDrawable()); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); } }
From source file:com.example.shoe.DirectionsTest.java
public LatLng getDestinationCoordinates(String picID) { // call DB method DatabaseHandler mDB = new DatabaseHandler(this); try {//w ww. jav a 2s . co m mDB.createDatabase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } try { mDB.openDatabase(); } catch (SQLException sqle) { throw sqle; } double mLat = 0; double mLon = 0; String place = null; Cursor mPlaces = mDB.fetchPicforId(picID); if (mPlaces != null) { mPlaces.moveToFirst(); // misnamed the columns ... FIX int mLatCol = mPlaces.getColumnIndex("longitude"); mLat = mPlaces.getDouble(mLatCol); // misnamed the columns ... FIX int mLonCol = mPlaces.getColumnIndex("latitude"); mLon = mPlaces.getDouble(mLonCol); int placeCol = mPlaces.getColumnIndex("name"); place = mPlaces.getString(placeCol); } mDB.close(); // get lat //double lat_value = Double.parseDouble(mLat); // get lon //double lon_value = Double.parseDouble(mLon); LatLng mDestination = new LatLng(mLat, mLon); //mDestination.latitude = 45.123456; Context context = getApplicationContext(); CharSequence text = "Your place is " + mDestination.latitude + " , " + mDestination.longitude + "\n" + "Place : " + place; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); //getLocation(); //mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapFrag)).getMap(); //LatLng destMarker = new LatLng(mDestination.latitude, mDestination.longitude); return mDestination; }
From source file:android.support.v7.widget.SwitchCompat.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int opticalInsetLeft = 0; int opticalInsetRight = 0; if (mThumbDrawable != null) { final Rect trackPadding = mTempRect; if (mTrackDrawable != null) { mTrackDrawable.getPadding(trackPadding); } else {/*from w w w .j av a2 s. c o m*/ trackPadding.setEmpty(); } final Rect insets = DrawableUtils.getOpticalBounds(mThumbDrawable); opticalInsetLeft = Math.max(0, insets.left - trackPadding.left); opticalInsetRight = Math.max(0, insets.right - trackPadding.right); } final int switchRight; final int switchLeft; if (ViewUtils.isLayoutRtl(this)) { switchLeft = getPaddingLeft() + opticalInsetLeft; switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight; } else { switchRight = getWidth() - getPaddingRight() - opticalInsetRight; switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight; } final int switchTop; final int switchBottom; switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) { default: case Gravity.TOP: switchTop = getPaddingTop(); switchBottom = switchTop + mSwitchHeight; break; case Gravity.CENTER_VERTICAL: switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2; switchBottom = switchTop + mSwitchHeight; break; case Gravity.BOTTOM: switchBottom = getHeight() - getPaddingBottom(); switchTop = switchBottom - mSwitchHeight; break; } mSwitchLeft = switchLeft; mSwitchTop = switchTop; mSwitchBottom = switchBottom; mSwitchRight = switchRight; }