android 缩放控制(ZoomControls)

android 缩放控制(ZoomControls)_第1张图片

 

 

在main.xml中

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    android:gravity="center_horizontal">

 

    <TextView

        android:id="@+id/text"

        android:layout_marginTop="15dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textSize="20dp"

        android:text="不积跬步无以至千里" />

  <ZoomControls

      android:id="@+id/zoomcontrols"

      android:layout_marginTop="15dp"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"

      android:gravity="bottom"/>

</LinearLayout>

 

 

 

 

在MyZoomControlsDemo.java程序中

package com.li.zoomcontrols;

 

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 TextView text = null;

  private ZoomControls zoomControls = null;

  private int size = 20; //保存文字大小的变量

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        super.setContentView(R.layout.main);

        this.text = (TextView)super.findViewById(R.id.text);

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

        this.zoomControls.setOnZoomInClickListener(new OnZoomInClickListenerImpl());

        this.zoomControls.setOnZoomOutClickListener(new OnZoomOutClickListenerImpl());

    }

    private class OnZoomInClickListenerImpl implements OnClickListener{

 

     public void onClick(View v) {

       MyZoomControlsDemo.this.size = size + 2;

       MyZoomControlsDemo.this.text.setTextSize(size);

     }

    }

    private class OnZoomOutClickListenerImpl implements OnClickListener{

 

     public void onClick(View v) {

       MyZoomControlsDemo.this.size = size - 2;

       MyZoomControlsDemo.this.text.setTextSize(size);

     }

    }

}



 

你可能感兴趣的:(android 缩放控制(ZoomControls))