Preface
This chapter is about Android. widget. zoomcontrols. translated as a scaling control. Translated from jiahuibin. Thanks again! I look forward to your participation in Android API Chinese translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://www.cnblogs.com/over140/
Body
I. Structure
Public class zoomcontrols extends linearlayout
Java. Lang. Object
Android. View. View
Android. View. viewgroup
Android. widget. linearlayout
Android. widget. zoomcontrols
Ii. Overview
Zoomcontrols displays a simple setting to control scaling and call back registered events.
Iii. Public Methods
Public Boolean hasfocus ()
If the view gets the focus, the returned result is true.
Return Value
If the view gets the focus, the returned result is true.
Public void hide ()
This method can hide the zoomcontrol view without displaying it.
Public Boolean ontouchevent (motionevent event)
This method handles touch screen movement events.
Parameters
Event.
Return Value
If it is true, the event is a touch, and vice versa, false is returned.
Public void setiszoominenabled (Boolean isenabled)
This method can be used to set whether the zoom button is available.
Parameters
If isenabled is true, the zoom-in button is available, and vice versa (the button turns gray ).
Public void setiszoomoutenabled (Boolean isenabled)
This method can be used to set whether the zoom button is available.
Parameters
If isenabled is true, the zoom button is available, and vice versa (the button turns gray ).
Public void setonzoominclicklistener (view. onclicklistener listener)
Register the enlarge listener
Parameters
Listener click the zoom in button to trigger the event. (Note: For an instance of onclicklistener, The onclick method can be rewritten, which contains specific response actions. I think this method also has the following methods as the focus of this class. We can implement corresponding actions in it to respond to our events .)
Public void setonzoomoutclicklistener (view. onclicklistener listener)
Register and narrow down the listener
Parameters
Listener click the zoom-in button to trigger the event. (Note: For the onclicklistener instance, you can rewrite the onclick method, which contains specific response actions .)
Public void setzoomspeed (long speed)
Set the scaling speed.
Parameters
Speed scaling speed
Public void show ()
This method corresponds to the hide method to display zoomcontrol.
Iv. Supplement
4.1 article link
[Recommendation] zoomcontrols scaling Control for Android Control
Zoomcontrls is always displayed on the map
[Recommended] use of zoomcontrols in Google Map
4.2 Sample Code (the translator declares that part of the code comes from a blog on the Internet. I would like to explain it here .)
4.2.1 Java File
Public class zoomcotroltest extends activity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
This. setcontentview (R. layout. Main );
Settitle ("zoomcontrols ");
Zoomcontrols = (zoomcontrols) This. findviewbyid (R. Id. zoomcontrols );
Zoomcontrols. Hide ();
Zoomcontrols. Show ();
// Setonzoominclicklistener ()-responds to the event of clicking the zoom in button
Zoomcontrols. setiszoominenabled (true );
Zoomcontrols. setiszoomoutenabled (true );
Zoomcontrols. setonzoominclicklistener (New onclicklistener (){
Public void onclick (view v ){
Toast. maketext (zoomcotroltest. This, "click the zoom in button", Toast. length_short). Show ();
}
});
// Setonzoomoutclicklistener ()-responds to the event of clicking the zoom out button
Zoomcontrols. setonzoomoutclicklistener (New onclicklistener (){
Public void onclick (view v ){
Toast. maketext (zoomcotroltest. This, "click the zoom out button", Toast. length_short). Show ();
}
});
}
}
4.2.2 XML file
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<! --
Zoom in/out button control
-->
<Zoomcontrols Android: Id = "@ + ID/zoomcontrols"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
</Zoomcontrols>
</Linearlayout>
4.2.3 download code
/Files/over140/2010/10/demo_zoomcontrols.rar
End
Thanks to jiahuibin for its hard translation and complete and sample code. You are welcome to provide more instructions on zoomcontrols :)