zoukankan      html  css  js  c++  java
  • 控件: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);
    }
    }
    }

  • 相关阅读:
    用AutoHotkey实现 iThoughts 思维导图节点文本一键转到Excel
    AutoHotkey+BUG小狼毫+BUG win10输入法设置的艰难摸索(未完待续)
    什么时候用接口,什么时候用抽象类?
    Java接口
    单例设计模式和多例
    MySQL大小写
    SQL LIKE 操作符
    SQL DELETE 语句
    IDEA自动补全返回值类型的快捷键
    IDEA导入jar包
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379402.html
Copyright © 2011-2022 走看看