控件:ZoomControls --- 缩放控制

 

main.xml

View Code
<?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
="Android控件---ZoomControls"
android:textSize
="10px" />
<ZoomControls
android:id="@+id/zoomcontrols"
android:layout_gravity
="bottom"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content" />
</LinearLayout>

 

MyZoomControlsDemo.java

View Code
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 MyZoomControlsDemo extends Activity {
// 缩放组件
private ZoomControls zoomControls;
private int size = 10; // 默认文字大小
private TextView text; // 文本显示组件

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 调用默认布局
super.setContentView(R.layout.main);
this.zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
// 取得组件
this.text = (TextView) findViewById(R.id.text);
// 设置放大监听
this.zoomControls.setOnZoomInClickListener(new OnZoomInClickListenerImpl());
// 设置缩小监听
this.zoomControls.setOnZoomOutClickListener(new OnZoomOutClickListenerImpl());
}

private class OnZoomInClickListenerImpl implements OnClickListener {

@Override
public void onClick(View view) {
// 更改文字大小
MyZoomControlsDemo.this.size = size + 2;
// 更改文字大小
MyZoomControlsDemo.this.text.setTextSize(size);
}
}

private class OnZoomOutClickListenerImpl implements OnClickListener {

@Override
public void onClick(View view) {
// 更改文字大小
MyZoomControlsDemo.this.size = size - 2;
// 更改文字大小
MyZoomControlsDemo.this.text.setTextSize(size);
}
}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2012-03-04 17:15  大米稀饭  阅读(667)  评论(0编辑  收藏  举报