AI2 Component  (Version nb184)
AlignmentUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime.util;
8 
9 import android.view.Gravity;
12 
18 public class AlignmentUtil {
19  LinearLayout viewLayout;
20 
21  public AlignmentUtil(LinearLayout viewLayout) {
22  this.viewLayout = viewLayout;
23  }
24 
30  public void setHorizontalAlignment (int alignment) throws IllegalArgumentException {
31  switch (alignment) {
33  viewLayout.setHorizontalGravity(Gravity.LEFT);
34  break;
36  viewLayout.setHorizontalGravity(Gravity.RIGHT);
37  break;
39  viewLayout.setHorizontalGravity(Gravity.CENTER_HORIZONTAL);
40  break;
41  default:
42  throw new IllegalArgumentException("Bad value to setHorizontalAlignment: " + alignment);
43  }
44  }
45 
51  public void setVerticalAlignment (int alignment) throws IllegalArgumentException {
52  switch (alignment) {
54  viewLayout.setVerticalGravity(Gravity.TOP);
55  break;
57  viewLayout.setVerticalGravity(Gravity.CENTER_VERTICAL);
58  break;
60  viewLayout.setVerticalGravity(Gravity.BOTTOM);
61  break;
62  default:
63  throw new IllegalArgumentException("Bad value to setVerticalAlignment: " + alignment);
64  }
65  }
66 }
67 
68 
69 
70 
71 
72 
com.google.appinventor.components
com.google.appinventor.components.common.ComponentConstants.GRAVITY_LEFT
static final int GRAVITY_LEFT
Definition: ComponentConstants.java:55
com.google.appinventor.components.runtime.LinearLayout.setVerticalGravity
void setVerticalGravity(int gravity)
Definition: LinearLayout.java:119
com.google.appinventor.components.common.ComponentConstants.GRAVITY_CENTER_VERTICAL
static final int GRAVITY_CENTER_VERTICAL
Definition: ComponentConstants.java:60
com.google.appinventor.components.runtime.util.AlignmentUtil.setHorizontalAlignment
void setHorizontalAlignment(int alignment)
Definition: AlignmentUtil.java:30
com.google.appinventor.components.common.ComponentConstants.GRAVITY_TOP
static final int GRAVITY_TOP
Definition: ComponentConstants.java:59
com.google.appinventor.components.runtime.util.AlignmentUtil
Definition: AlignmentUtil.java:18
com.google.appinventor.components.runtime.util.AlignmentUtil.setVerticalAlignment
void setVerticalAlignment(int alignment)
Definition: AlignmentUtil.java:51
com.google.appinventor.components.runtime.LinearLayout.setHorizontalGravity
void setHorizontalGravity(int gravity)
Definition: LinearLayout.java:115
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.runtime.util.AlignmentUtil.AlignmentUtil
AlignmentUtil(LinearLayout viewLayout)
Definition: AlignmentUtil.java:21
com.google.appinventor.components.common.ComponentConstants.GRAVITY_CENTER_HORIZONTAL
static final int GRAVITY_CENTER_HORIZONTAL
Definition: ComponentConstants.java:57
com.google.appinventor.components.common.ComponentConstants.GRAVITY_BOTTOM
static final int GRAVITY_BOTTOM
Definition: ComponentConstants.java:61
com.google
com
com.google.appinventor.components.common.ComponentConstants
Definition: ComponentConstants.java:13
com.google.appinventor.components.runtime.LinearLayout
Definition: LinearLayout.java:20
com.google.appinventor.components.common.ComponentConstants.GRAVITY_RIGHT
static final int GRAVITY_RIGHT
Definition: ComponentConstants.java:56
com.google.appinventor