Public Constructors
public GridView (Context context)
Since: API Level 1public GridView (Context context, AttributeSet attrs)
Since: API Level 1public GridView (Context context, AttributeSet attrs, int defStyle)
Since: API Level 1Public Methods
public ListAdapter getAdapter ()
Since: API Level 1Returns the adapter currently associated with this widget.
Returns
- The adapter used to provide this view's content.
public int getNumColumns ()
Since: API Level 11Get the number of columns in the grid. Returns
AUTO_FIT
if the Grid has never been laid out.Related XML Attributes
See Also
public int getStretchMode ()
Since: API Level 1public boolean onKeyDown (int keyCode, KeyEvent event)
Since: API Level 1Default implementation of
KeyEvent.Callback.onKeyDown()
:
perform press of the view when KEYCODE_DPAD_CENTER
or KEYCODE_ENTER
is released, if the view is enabled and clickable.Parameters
keyCode | A key code that represents the button pressed, from KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Returns
- If you handled the event, return true. If you want to allow
the event to be handled by the next receiver, return false.
public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event)
Since: API Level 1Default implementation of
KeyEvent.Callback.onKeyMultiple()
:
always returns false (doesn't handle the event).Parameters
keyCode | A key code that represents the button pressed, from KeyEvent . |
---|---|
repeatCount | The number of times the action was made. |
event | The KeyEvent object that defines the button action. |
Returns
- If you handled the event, return true. If you want to allow
the event to be handled by the next receiver, return false.
public boolean onKeyUp (int keyCode, KeyEvent event)
Since: API Level 1Default implementation of
KeyEvent.Callback.onKeyUp()
:
perform clicking of the view when KEYCODE_DPAD_CENTER
or KEYCODE_ENTER
is released.Parameters
keyCode | A key code that represents the button pressed, from KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Returns
- If you handled the event, return true. If you want to allow
the event to be handled by the next receiver, return false.
public void setAdapter (ListAdapter adapter)
Since: API Level 1Sets the data behind this GridView.
Parameters
adapter | the adapter providing the grid's data |
---|
public void setColumnWidth (int columnWidth)
Since: API Level 1Set the width of columns in the grid.
Related XML Attributes
Parameters
columnWidth | The column width, in pixels. |
---|
public void setGravity (int gravity)
Since: API Level 1Describes how the child views are horizontally aligned. Defaults to Gravity.LEFT
Related XML Attributes
Parameters
gravity | the gravity to apply to this grid's children |
---|
public void setHorizontalSpacing (int horizontalSpacing)
Since: API Level 1Set the amount of horizontal (x) spacing to place between each item in the grid.
Related XML Attributes
Parameters
horizontalSpacing | The amount of horizontal space between items, in pixels. |
---|
public void setNumColumns (int numColumns)
Since: API Level 1Set the number of columns in the grid
Related XML Attributes
Parameters
numColumns | The desired number of columns. |
---|
public void setRemoteViewsAdapter (Intent intent)
Since: API Level 11Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.
Parameters
intent | the intent used to identify the RemoteViewsService for the adapter to connect to. |
---|
public void setSelection (int position)
Since: API Level 1Sets the currently selected item
Parameters
position | Index (starting at 0) of the data item to be selected. If in touch mode, the item will not be selected but it will still be positioned appropriately. |
---|
public void setStretchMode (int stretchMode)
Since: API Level 1Control how items are stretched to fill their space.
Related XML Attributes
Parameters
stretchMode | Either NO_STRETCH ,
STRETCH_SPACING ,
STRETCH_SPACING_UNIFORM ,
or STRETCH_COLUMN_WIDTH . |
---|
public void setVerticalSpacing (int verticalSpacing)
Since: API Level 1Set the amount of vertical (y) spacing to place between each item in the grid.
Related XML Attributes
Parameters
verticalSpacing | The amount of vertical space between items, in pixels. |
---|
public void smoothScrollByOffset (int offset)
Since: API Level 11Smoothly scroll to the specified adapter position offset. The view will scroll such that the indicated position is displayed.
Parameters
offset | The amount to offset from the adapter position to scroll to. |
---|
public void smoothScrollToPosition (int position)
Since: API Level 8Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Parameters
position | Scroll to this adapter position. |
---|
Protected Methods
protected void attachLayoutAnimationParameters (View child, ViewGroup.LayoutParams params, int index, int count)
Since: API Level 1Subclasses should override this method to set layout animation parameters on the supplied child.
Parameters
child | the child to associate with animation parameters |
---|---|
params | the child's layout parameters which hold the animation parameters |
index | the index of the child in the view group |
count | the number of children in the view group |
protected int computeVerticalScrollExtent ()
Since: API Level 1Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeVerticalScrollRange()
and computeVerticalScrollOffset()
.The default extent is the drawing height of this view.
Returns
- the vertical extent of the scrollbar's thumb
protected int computeVerticalScrollOffset ()
Since: API Level 1Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeVerticalScrollRange()
and computeVerticalScrollExtent()
.The default offset is the scroll offset of this view.
Returns
- the vertical offset of the scrollbar's thumb
protected int computeVerticalScrollRange ()
Since: API Level 1Compute the vertical range that the vertical scrollbar represents.
The range is expressed in arbitrary units that must be the same as the units used by
computeVerticalScrollExtent()
and computeVerticalScrollOffset()
.Returns
- the total vertical range represented by the vertical
scrollbar
The default range is the drawing height of this view.
protected void layoutChildren ()
Since: API Level 1Subclasses must override this method to layout their children.
protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.
Parameters
gainFocus | True if the View has focus; false otherwise. |
---|---|
direction | The direction focus has moved when requestFocus() is called to
give this view focus. Values are FOCUS_UP ,
FOCUS_DOWN ,
FOCUS_LEFT ,
FOCUS_RIGHT ,
FOCUS_FORWARD ,
or FOCUS_BACKWARD .
It may not always apply, in which case use the default. |
previouslyFocusedRect | The rectangle, in this view's coordinate system, of the
previously focused view. If applicable, this will be passed in as
finer grained information about where the focus is coming from (in
addition to direction). Will be null
otherwise.
|
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Since: API Level 1Measure the view and its content to determine the measured width and the measured height. This method is invoked by
measure(int,
int)
and should be overriden by subclasses to provide
accurate and efficient measurement of their contents.
CONTRACT: When overriding this method, you must call
setMeasuredDimension(int,
int)
to store the measured width and height of this view.
Failure to do so will trigger an IllegalStateException
,
thrown by measure(int,
int)
. Calling the superclass' onMeasure(int,
int)
is a valid use.
The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override
onMeasure(int,
int)
to provide better measurements of their content.
If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (
getSuggestedMinimumHeight()
and getSuggestedMinimumWidth()
).
Parameters
widthMeasureSpec | horizontal space requirements as imposed by the parent. The
requirements are encoded with View.MeasureSpec . |
---|---|
heightMeasureSpec | vertical space requirements as imposed by the parent. The
requirements are encoded with View.MeasureSpec . |
GridView
using adapters
No comments:
Post a Comment