List of usage examples for android.view Gravity LEFT
int LEFT
To view the source code for android.view Gravity LEFT.
Click Source Link
From source file:Main.java
public static void preDraw(TextView view, Canvas canvas) { Drawable[] drawables = view.getCompoundDrawables(); if (drawables != null) { if (drawables[0] != null) { view.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); onCenterDraw(view, canvas, drawables[0], Gravity.LEFT); } else if (drawables[1] != null) { view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP); onCenterDraw(view, canvas, drawables[1], Gravity.TOP); } else if (drawables[2] != null) { view.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); onCenterDraw(view, canvas, drawables[2], Gravity.RIGHT); } else if (drawables[3] != null) { view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); onCenterDraw(view, canvas, drawables[3], Gravity.BOTTOM); }//w w w . j a v a2 s . c o m } }
From source file:Main.java
public static WindowManager.LayoutParams makeLayout(int x, int y, int width, int height) { WindowManager.LayoutParams ll_lp;/*from w w w . j a v a 2s. c o m*/ //Just a sample layout parameters. ll_lp = new WindowManager.LayoutParams(); ll_lp.format = PixelFormat.OPAQUE; ll_lp.height = height; ll_lp.width = width; ll_lp.gravity = Gravity.LEFT | Gravity.TOP; ll_lp.x = x; ll_lp.y = y; ll_lp.token = null; //ll_lp.gravity |= Gravity.CENTER_HORIZONTAL; //ll_lp.gravity |= Gravity.CENTER_VERTICAL; ll_lp.type = WindowManager.LayoutParams.TYPE_APPLICATION; ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; return ll_lp; }
From source file:Main.java
public final static int[] getPopupPosition(View anchor, int gravity) { int[] position = new int[2]; int windowWidth = anchor.getRootView().getMeasuredWidth(); int windowHeight = anchor.getRootView().getMeasuredHeight(); int anchorWidth = anchor.getMeasuredWidth(); int anchorHeight = anchor.getMeasuredHeight(); int[] location = new int[2]; anchor.getLocationInWindow(location); if (Gravity.LEFT == (gravity & Gravity.LEFT)) { position[0] = location[0];/* w ww . j a v a 2s. co m*/ } else if (Gravity.RIGHT == (gravity & Gravity.RIGHT)) { position[0] = windowWidth - location[0] - anchorWidth; } if (Gravity.TOP == (gravity & Gravity.TOP)) { position[1] = location[1] + anchorHeight; } else if (Gravity.BOTTOM == (gravity & Gravity.BOTTOM)) { position[1] = windowHeight - location[1]; } return position; }
From source file:Main.java
protected static WindowManager.LayoutParams updateLayoutParams(boolean left, int y, WindowManager.LayoutParams params) { if (left) {/*ww w .j a v a 2s . c o m*/ params.gravity = Gravity.LEFT | Gravity.TOP; } else { params.gravity = Gravity.RIGHT | Gravity.TOP; } params.y = y; return params; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Layout.Alignment getLayoutAlignment(TextView textView) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return Layout.Alignment.ALIGN_NORMAL; }/*w w w . j av a 2 s .com*/ Layout.Alignment alignment; switch (textView.getTextAlignment()) { case TextView.TEXT_ALIGNMENT_GRAVITY: switch (textView.getGravity() & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case Gravity.END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.LEFT: alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL; break; case Gravity.RIGHT: alignment = (textView.getLayoutDirection() == TextView.LAYOUT_DIRECTION_RTL) ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE; break; case Gravity.CENTER_HORIZONTAL: alignment = Layout.Alignment.ALIGN_CENTER; break; default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } break; case TextView.TEXT_ALIGNMENT_TEXT_START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case TextView.TEXT_ALIGNMENT_TEXT_END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case TextView.TEXT_ALIGNMENT_CENTER: alignment = Layout.Alignment.ALIGN_CENTER; break; case TextView.TEXT_ALIGNMENT_VIEW_START: alignment = Layout.Alignment.ALIGN_NORMAL; break; case TextView.TEXT_ALIGNMENT_VIEW_END: alignment = Layout.Alignment.ALIGN_OPPOSITE; break; case TextView.TEXT_ALIGNMENT_INHERIT: // default: alignment = Layout.Alignment.ALIGN_NORMAL; break; } return alignment; }
From source file:com.jakewharton.behavior.drawer.DrawerBehavior.java
private static void validateGravity(int gravity) { if (gravity != Gravity.LEFT && gravity != Gravity.RIGHT && gravity != GravityCompat.START && gravity != GravityCompat.END) { throw new IllegalArgumentException("Only START, END, LEFT, or RIGHT gravity is supported."); }//from w w w .j a v a2s . com }
From source file:Main.java
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) { int drawablePadding = view.getCompoundDrawablePadding(); int ratio = 1; float total;/*from w w w . jav a 2 s.c om*/ switch (gravity) { case Gravity.RIGHT: ratio = -1; case Gravity.LEFT: total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight(); canvas.translate(ratio * (view.getWidth() - total) / 2, 0); break; case Gravity.BOTTOM: ratio = -1; case Gravity.TOP: Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics(); total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom(); canvas.translate(0, ratio * (view.getHeight() - total) / 2); break; } }
From source file:com.mattermost.service.Promise.java
public static PopupWindow show() { Activity currentActivity = AppActivity.current; PopupWindow pw = new PopupWindow(currentActivity); pw.setFocusable(false);/*from w w w . j a v a 2 s . c o m*/ pw.setBackgroundDrawable(new ColorDrawable(0)); ImageView img = new ImageView(currentActivity); pw.setContentView(img); View view = currentActivity.getWindow().getDecorView(); pw.setWidth(60); pw.setHeight(60); AnimatedCircleDrawable a = new AnimatedCircleDrawable(Color.RED, 5, Color.TRANSPARENT, 30); img.setImageDrawable(a); pw.showAtLocation(view, Gravity.LEFT | Gravity.TOP, view.getWidth() / 2 - 30, view.getHeight() / 2 - 30); a.start(); return pw; }
From source file:com.aetherfoundry.searchers.NavigationDrawerUtil.java
/** * * @param appCompatActivity provide the instance of activity * @param drawerLayout provide the instance of drawerLayout * that's inflated at the activity/*from w w w . ja v a 2 s .co m*/ * @param drawerCallback provide the callback of drawerLayout actions * @return a new instance of ActionBarDrawerToggle based on the params */ public static ActionBarDrawerToggle configNavigationDrawer(AppCompatActivity appCompatActivity, DrawerLayout drawerLayout, final DrawerCallback drawerCallback) { if (appCompatActivity == null || drawerLayout == null) { return null; } drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(appCompatActivity, drawerLayout, R.string.app_name, R.string.app_name) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (drawerCallback != null) { drawerCallback.onDrawerOpened(); } } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (drawerCallback != null) { drawerCallback.onDrawerClosed(); } } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (drawerCallback != null) { drawerCallback.onDrawerSlide(drawerView, slideOffset); } } }; drawerLayout.setDrawerListener(actionBarDrawerToggle); return actionBarDrawerToggle; }
From source file:cn.foxnickel.listentome.view.ViewUtil.java
public static View getWordsView(Context context, String word, @ColorRes int color, boolean isTextSelectable) { TextView tv = new TextView(context); tv.setTextColor(ContextCompat.getColor(context, color)); tv.setPadding(0, 6, 0, 6);// w ww. j a v a 2s . co m tv.setTextSize(16); tv.setTextIsSelectable(isTextSelectable); tv.setGravity(Gravity.LEFT); tv.setText(word); return tv; }