目录搜索
androidManifestManifest.permissionManifest.permission_groupandroid.accessibilityserviceAccessibilityServiceandroid.accountsAccountandroid.appNotificationManagerandroid.bluetoothBluetoothAdapterBluetoothClassBluetoothClass.DeviceBluetoothClass.Device.MajorBluetoothClass.ServiceBluetoothDeviceBluetoothServerSocketBluetoothSocketandroid.contentSharedPreferencesandroid.database.sqliteSQLiteCursorDriverSQLiteOpenHelperandroid.graphicsBitmapandroid.locationLocationListenerGeocoderGpsStatusGpsStatus.ListenerGpsStatus.NmeaListenerGpsSatelliteandroid.mediaAudioFormatAsyncPlayerAudioRecordAudioRecord.OnRecordPositionUpdateListenerThumbnailUtilsAudioManagerandroid.netTrafficStatsMailToLocalSocketandroid.osAsyncTaskAsyncTask.StatusCountDownTimerMessageMessageQueueHandlerThreadandroid.textHtmlandroid.utilJsonWriterandroid.viewContextMenuContextMenu.ContextMenuInfoDisplayViewManagerViewViewStubViewTreeObserverViewParentWindowManagerGestureDetectorGravityMenuInflaterScaleGestureDetectorSoundEffectConstantsandroid.view.inputmethodInputConnectionInputMethodInputMethodSessionBaseInputConnectionInputMethodManagerandroid.widgetAbsListViewAbsListView.LayoutParamsAbsListView.OnScrollListenerAbsListView.RecyclerListenerAbsoluteLayoutAbsoluteLayout.LayoutParamsAbsSeekBarAbsSpinnerAdapterViewAdapterView.AdapterContextMenuInfoAdapterView.OnItemLongClickListenerAdapterView.OnItemSelectedListenerAdapterView.OnItemClickListenerAnalogClockBaseAdapterBaseExpandableListAdapterButtonCheckBoxCheckedTextViewCheckableChronometerChronometer.OnChronometerTickListenerCompoundButtonCompoundButton.OnCheckedChangeListenerCursorAdapterCursorTreeAdapterDatePickerDatePicker.OnDateChangedListenerDialerFilterDigitalClockEditTextFilterFilter.FilterListenerFilter.FilterResultsExpandableListAdapterExpandableListView.OnChildClickListenerExpandableListView.OnGroupClickListenerExpandableListView.OnGroupCollapseListenerExpandableListView.OnGroupExpandListenerFilterableGalleryGallery.LayoutParamsGridViewGridLayoutGridLayout.AlignmentRadioGroupImageViewImageView.ScaleTypeHorizontalScrollViewImageButtonImageSwitcherFilterQueryProviderListAdapterListViewMediaControllerMultiAutoCompleteTextViewMultiAutoCompleteTextView.CommaTokenizerMultiAutoCompleteTextView.TokenizerQuickContactBadgeRadioButtonRatingBarRatingBar.OnRatingBarChangeListenerRelativeLayoutRemoteViewsResourceCursorAdapterResourceCursorTreeAdapterScrollerScrollViewSearchViewSearchView.OnCloseListenerSearchView.OnQueryTextListenerSearchView.OnSuggestionListenerSeekBarSeekBar.OnSeekBarChangeListenerSimpleAdapterSimpleAdapter.ViewBinderSimpleCursorAdapterSimpleCursorAdapter.CursorToStringConverterSimpleCursorAdapter.ViewBinderSimpleCursorTreeAdapterSimpleCursorTreeAdapter.ViewBinderSimpleExpandableListAdapterSlidingDrawerSlidingDrawer.OnDrawerCloseListenerSlidingDrawer.OnDrawerOpenListenerSlidingDrawer.OnDrawerScrollListenerSpinnerSpinnerAdapterWrapperListAdapterTabHostTabHost.TabSpecTextViewTimePickerTimePicker.OnTimeChangedListenerToastTableLayoutTableLayout.LayoutParamsTableRowTableRow.LayoutParamsTabWidgetTextSwitcherToggleButtonTwoLineListItemVideoViewViewAnimatorViewFlipperViewSwitcherViewSwitcher.ViewFactoryZoomButtonsControllerZoomButtonsController.OnZoomListenerZoomButtonZoomControlsdalvik.systemDexFile
文字


ZoomControls

联系译者:huibin.jia@gmail.com

2010-10-22

版本:Android 2.2 r1

一、类结构

         public class ZoomControls extends LinearLayout

 

         java.lang.Object

                   android.view.View

                          android.view.ViewGroup

                                     android.widget.LinearLayout

                                               android.widget.ZoomControls

 

二、概述

        

ZoomControl显示一个简单的设置来控制缩放并回调已注册的事件。

        

三、公共方法

         public boolean hasFocus ()

         如果这个视图获得了焦点就返回真。

                   返回值

                            如果这个视图获得了焦点就返回真。

 

         public void hide ()

         这个方法可以将zoomControl视图隐藏起来,不显示。

 

         public boolean onTouchEvent (MotionEvent event)

    这个方法处理触摸屏移动事件。

                   参数

                            event该移动事件.

                   返回值

                   如果是true,该事件是触摸,反之返回false

 

         public void setIsZoomInEnabled (boolean isEnabled)

         这个方法可以设置放大按钮是否可用。

                   参数

                   isEnabled 如果是true,放大按钮可用,反之不可用(按钮变成灰色)。

 

         public void setIsZoomOutEnabled (boolean isEnabled)

         这个方法可以设置缩小按钮是否可用。

       参数

                   isEnabled  如果是true缩小按钮可用,反之不可用(按钮变成灰色)。

 

         public void setOnZoomInClickListener (View.OnClickListener listener)

         注册放大监听器

                   参数

Listener 点击放大按钮事件触发的事件。(译者注:为OnClickListener的实例,可以复写onClick方法,里面为具体的响应动作。我感觉这个方法还有下面的方法是本类的重点,我们可以在里面实现相应的动作,来响应我们的事件。)

 

         public void setOnZoomOutClickListener (View.OnClickListener listener)

         注册缩小监听器

                   参数

Listener点击缩小按钮事件触发的事件。(译者注:为OnClickListener的实例,可以复写onClick方法,里面为具体的响应动作。)

 

         public void setZoomSpeed (long speed)

设置缩放速度。

                   参数

                            Speed 缩放速度

 

         public void show () 

         这个方法和hide方法对应,用来显示ZoomControl

 

四、代码

         声明:这个代码部分思路来源于网络上一个博客,谨以此来解释,特此声明。

package com.jhb.zoomcontroltest;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Toast;

import android.widget.ZoomControls;

 

public class ZoomCotroltest extends Activity {

 

        @Override

        protected void onCreate(Bundle savedInstanceState) {

                // TODO Auto-generated method stub

                super.onCreate(savedInstanceState);

                this.setContentView(R.layout.main);

 

                setTitle("ZoomControls");

 

                ZoomControls zoomControls = (ZoomControls) this.findViewById(R.id.zoomControls);

                zoomControls.hide();

                zoomControls.show();

                // setOnZoomInClickListener() - 响应单击放大按钮的事件

                zoomControls.setIsZoomInEnabled(true);

                zoomControls.setIsZoomOutEnabled(true);

                zoomControls.setOnZoomInClickListener(new OnClickListener() {

                        public void onClick(View v) {

                                Toast.makeText(ZoomCotroltest.this, "单击了放大按钮", Toast.LENGTH_SHORT).show();

                        }

                });

                

                // setOnZoomOutClickListener() - 响应单击缩小按钮的事件

                zoomControls.setOnZoomOutClickListener(new OnClickListener() {

                        public void onClick(View v) {

                                Toast.makeText(ZoomCotroltest.this, "单击了缩小按钮", Toast.LENGTH_SHORT).show();        

                        }

                });

 

        }

}

 

它对应的布局文件是下面这样的:

<?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">

        <!--

                放大/缩小按钮控件

        -->

        <ZoomControls android:id="@+id/zoomControls"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content">

        </ZoomControls>

</LinearLayout>


上一篇:下一篇: