Android 兩點縮放字體源碼工程下載:
免費下載地址在 http://linux.linuxidc.com/
用戶名與密碼都是www.linuxidc.com
具體下載目錄在 /pub/Android源碼集錦/2011年/11月/Android 兩點縮放字體/
MultiTouchTestActivity
-
- package src.youer.text;
-
-
- import java.io.InputStream;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TextView;
-
- public class MultiTouchTestActivity extends Activity
- {
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- TextView textView = (TextView) this.findViewById(R.id.text_view);
- try
- {
- textView.setText(readText());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- float zoomScale = 0.5f;// 縮放比例
- new ZoomTextView(textView, zoomScale);
- }
-
- /**
- * 讀取txt
- *
- * @param str
- * @return
- * @throws Exception
- */
- public String readText() throws Exception
- {
- InputStream is = this.getClass()
- .getResourceAsStream("/assets/text.txt");
- int index = is.available();
- byte data[] = new byte[index];
- is.read(data);
- return new String(data, "UTF-8");
- }
- }
ZoomTextView
- package src.youer.text;
-
- import android.widget.TextView;
-
- public class ZoomTextView extends ZoomView<TextView>
- {
- /** 最小字體 */
- public static final float MIN_TEXT_SIZE = 10f;
-
- /** 最大子圖 */
- public static final float MAX_TEXT_SIZE = 100.0f;
-
- /** 縮放比例 */
- float scale;
-
- /** 設置字體大小 */
- float textSize;
-
- public ZoomTextView(TextView view, float scale)
- {
- super(view);
- this.scale = scale;
- textSize = view.getTextSize();
- }
-
- /**
- * 放大
- */
- protected void zoomOut()
- {
- textSize += scale;
- if (textSize > MAX_TEXT_SIZE)
- {
- textSize = MAX_TEXT_SIZE;
- }
- view.setTextSize(textSize);
- }
-
- /**
- * 縮小
- */
- protected void zoomIn()
- {
- textSize -= scale;
- if (textSize < MIN_TEXT_SIZE)
- {
- textSize = MIN_TEXT_SIZE;
- }
- view.setTextSize(textSize);
- }
-
- }