From 0b7413d5d6239b7bc43816bea5187b323a633b11 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Wed, 21 Mar 2012 14:51:41 -0700 Subject: GridView attribute updates Bring GridView's API in sync with its supported style attributes. Bug 6103758 Change-Id: Ib2c4d4d48061d23a7d886364965f0cb50c239e5d --- core/java/android/widget/GridView.java | 100 ++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) (limited to 'core/java/android/widget/GridView.java') diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index 739bcce1261d..0f1dab58ea7a 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -1908,7 +1908,8 @@ public class GridView extends AbsListView { } /** - * Describes how the child views are horizontally aligned. Defaults to Gravity.LEFT + * Set the gravity for this grid. Gravity describes how the child views + * are horizontally aligned. Defaults to Gravity.LEFT * * @param gravity the gravity to apply to this grid's children * @@ -1921,6 +1922,17 @@ public class GridView extends AbsListView { } } + /** + * Describes how the child views are horizontally aligned. Defaults to Gravity.LEFT + * + * @return the gravity that will be applied to this grid's children + * + * @attr ref android.R.styleable#GridView_gravity + */ + public int getGravity() { + return mGravity; + } + /** * Set the amount of horizontal (x) spacing to place between each item * in the grid. @@ -1937,6 +1949,44 @@ public class GridView extends AbsListView { } } + /** + * Returns the amount of horizontal spacing currently used between each item in the grid. + * + *

This is only accurate for the current layout. If {@link #setHorizontalSpacing(int)} + * has been called but layout is not yet complete, this method may return a stale value. + * To get the horizontal spacing that was explicitly requested use + * {@link #getRequestedHorizontalSpacing()}.

+ * + * @return Current horizontal spacing between each item in pixels + * + * @see #setHorizontalSpacing(int) + * @see #getRequestedHorizontalSpacing() + * + * @attr ref android.R.styleable#GridView_horizontalSpacing + */ + public int getHorizontalSpacing() { + return mHorizontalSpacing; + } + + /** + * Returns the requested amount of horizontal spacing between each item in the grid. + * + *

The value returned may have been supplied during inflation as part of a style, + * the default GridView style, or by a call to {@link #setHorizontalSpacing(int)}. + * If layout is not yet complete or if GridView calculated a different horizontal spacing + * from what was requested, this may return a different value from + * {@link #getHorizontalSpacing()}.

+ * + * @return The currently requested horizontal spacing between items, in pixels + * + * @see #setHorizontalSpacing(int) + * @see #getHorizontalSpacing() + * + * @attr ref android.R.styleable#GridView_horizontalSpacing + */ + public int getRequestedHorizontalSpacing() { + return mRequestedHorizontalSpacing; + } /** * Set the amount of vertical (y) spacing to place between each item @@ -1945,6 +1995,8 @@ public class GridView extends AbsListView { * @param verticalSpacing The amount of vertical space between items, * in pixels. * + * @see #getVerticalSpacing() + * * @attr ref android.R.styleable#GridView_verticalSpacing */ public void setVerticalSpacing(int verticalSpacing) { @@ -1954,6 +2006,19 @@ public class GridView extends AbsListView { } } + /** + * Returns the amount of vertical spacing between each item in the grid. + * + * @return The vertical spacing between items in pixels + * + * @see #setVerticalSpacing(int) + * + * @attr ref android.R.styleable#GridView_verticalSpacing + */ + public int getVerticalSpacing() { + return mVerticalSpacing; + } + /** * Control how items are stretched to fill their space. * @@ -1987,6 +2052,39 @@ public class GridView extends AbsListView { } } + /** + * Return the width of a column in the grid. + * + *

This may not be valid yet if a layout is pending.

+ * + * @return The column width in pixels + * + * @see #setColumnWidth(int) + * @see #getRequestedColumnWidth() + * + * @attr ref android.R.styleable#GridView_columnWidth + */ + public int getColumnWidth() { + return mColumnWidth; + } + + /** + * Return the requested width of a column in the grid. + * + *

This may not be the actual column width used. Use {@link #getColumnWidth()} + * to retrieve the current real width of a column.

+ * + * @return The requested column width in pixels + * + * @see #setColumnWidth(int) + * @see #getColumnWidth() + * + * @attr ref android.R.styleable#GridView_columnWidth + */ + public int getRequestedColumnWidth() { + return mRequestedColumnWidth; + } + /** * Set the number of columns in the grid * -- cgit v1.2.3