Android控件之ZoomControls缩放控件
先看一下效果
正常
缩小
放大
一、简介
ZoomControls是一组可缩放的控件。它包含俩个按钮(放大按钮、缩小按钮)
二、重要方法
hasFocus():判断焦点
hide():隐藏
onTouchEvent(MotionEvent event):现这个方法来处理触摸屏移动事件
setIsZoomInEnabled(boolean isEnabled):是否允许放大
setIsZoomOutEnabled(boolean isEnabled):是否允许缩小
setOnZoomInClickListener(View.OnClickListener listener):注册放大监听器
setOnZoomOutClickListener(View.OnClickListener listener):注册缩小监听器
setZoomSpeed(long speed):设置缩放速度
show():显示
三、实例
1.布局文件
<?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">
<TextView android:id="@+id/text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="ZoomControls实例"
android:textSize="12px" />
<ZoomControls android:id="@+id/zoomcontrols"
android:layout_gravity="bottom" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
2.Java代码
package com.wjq;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.ZoomControls;
public class ZoomControlsDemo extends Activity {
private ZoomControls zoomControls;
static long size = 12;
private TextView text;
/*
* (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.zoomcontrols);
setTitle("ZoomControls");
zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
text = (TextView) findViewById(R.id.text);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
size = size + 2;
text.setTextSize(size);
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
size = size - 2;
text.setTextSize(size);
}
});
}
}