direktori cari
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
watak


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>


Artikel sebelumnya: Artikel seterusnya: