In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use Android API", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Android API" this article.
I. Android API structure
PublicfinalclassGridViewextendsAbsListView java.lang.Object android.view.View android.view.ViewGroup android.widget.AdapterView android.widget.AbsListView android.widget.GridView
II. Overview of Android API class
A scrollable view component in Android API that displays multiple items on a plane, and the entries in the component are associated with the component through a ListAdapter. For example, the application displayed on the android phone:
For example, the realization of the ninth grid chart, using GridView is *, is also the simplest.
3. Android API constructor
Public Grid View (Contextcontext)
Create a GridView instance of the default property
Public GridView (Contextcontext,AttributeSetattrs)
Create an instance of GridView with the attrs attribute
Public GridView (Contextcontext,AttributeSetattrs,intdefStyle)
Create an instance of GridView with the attrs attribute and specify its default style
4. XML attribute in Android API
Attribute name description
Android:columnWidth sets the width of the column. The method of association is: setColumnWidth (int)
Android:gravity sets the location of the content in this component in the component. Optional values are: top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical can be selected, separated by "|". Association method: setGravity (intgravity)
The spacing between the two columns of android:horizontalSpacing. Association method: setHorizontalSpacing (int)
Number of android:numColumns columns. Association method: setNumColumns (int)
Android:stretchMode zoom mode. Association method: setStretchMode (int)
The spacing between the two lines of the android:verticalSpacing. Association method: setVerticalSpacing (int)
5. Android API Public method
PublicListAdaptergetAdapter ()
Get the adapter associated with this component..
Return value
ListAdapter adapter instance
PublicintgetStretchMode ()
Get the zoom mode of GridView..
Public boolean onKeyDown (intkeyCode,KeyEventevent)
By default, it is implemented by KeyEvent.Callback.onKeyMultiple (), and if the view is available and clickable, then passing in a KEYCODE_DPAD_CENTER or KEYCODE_ enter value is performed by pressing the view.
Parameters.
KeyCode a key value that represents a press operation.
Event represents the object of the button event.
Return value
If you think you have finished handling the event and do not want the next processor to handle the event, return true, otherwise return false.
Public boolean onKeyMultiple (intkeyCode,intrepeatCount,KeyEventevent)
It is implemented by default by KeyEvent.Callback.onKeyMultiple () and always returns false (this event is not handled).
Parameters.
KeyCode key value.
RepeatCount the number of times this action has occurred.
Event event object.
Return value
If you think you have finished handling the event and do not want the next processor to handle the event, return true, otherwise return false.
Public booleanonKeyUp (intkeyCode,KeyEventevent)
By default, it is implemented by KeyEvent.Callback.onKeyMultiple (), and if the view is available and clickable, then passing in a KEYCODE_DPAD_CENTER or KEYCODE_ enter value performs a click-view operation.
Parameters.
KeyCode key value.
Event event object.
Return value
If you think you have finished handling the event and do not want the next processor to handle the event, return true, otherwise return false.
Public void setAdapter (ListAdapteradapter)
Set the data for GridView.
Parameters.
Adapter adapters that provide data to grid
PublicvoidsetColumnWidth (intcolumnWidth)
Sets the column width of GridView.
Parameters.
The width of the columnWidth column, in pixels
PublicvoidsetGravity (intgravity)
Sets the location of the content of the control. The default value is: Gravity.LEFT.
Parameters.
Gravity position value
PublicvoidsetHorizontalSpacing (inthorizontalSpacing)
Sets the column spacing.
Parameters.
HorizontalSpacing column spacing value
Public void setNumColumns (intnumColumns)
Set the number of columns for grid
Parameters.
NumColumns column value.
Public void setSelection (intposition)
Set the selected entry.
Parameters.
Position. The index value of the data entry in the list (starting at 0). If you are in touchable mode, the entry under the index value will not be selected, but the index value still points to the entry.
Public void setStretchMode (intstretchMode)
Sets what zoom mode the entries in grid should use to fill the space. .
Parameters.
Available values for stretchMode: NO_STRETCH,STRETCH_SPACING,STRETCH_SPACING_UNIFORM, or STRETCH_COLUMN_WIDTH
Public void setVertical Spacing (intverticalSpacing)
Set the line spacing.
Parameters.
VerticalSpacing spacing value, in pixels
6. Android API code example
Here is a small example. Let's look at the effect first:
1. GridView01.java public class GridView01 extends Activity {private GridView gridview; @ Override protected void onCreate (Bundle savedInstanceState) {/ / TODO Auto-generated method stub super.onCreate (savedInstanceState); setContentView (R.layout.gridview); / / prepare the data entry to be added List items = new ArrayList (); for (int I = 0; I < 10) Map item +) {Map item = new HashMap (); item.put ("imageItem", R.drawable.icon); item.put ("textItem", "text" + I); items.add (item) Instantiate an adapter SimpleAdapter adapter = new SimpleAdapter (this, items, R.layout.grid_item, new String [] {"imageItem", "textItem"}, new int [] {R.id.image_item, R.id.text_item}); / / get GridView instance gridview = (GridView) findViewById (R.id.mygridview); / / gridview.setNumColumns (3) / / you can set / / gridview.setGravity (Gravity.CENTER) in xml; / / Ibid / / associate GridView with data adapter gridview.setAdapter (adapter);}} 2, gridview.xml 3, grid_item.xml are all the contents of this article "how to use Android API". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.