歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 兩點縮放字體

Android 兩點縮放字體

日期:2017/3/1 11:08:16   编辑:Linux編程

Android 兩點縮放字體源碼工程下載:

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /pub/Android源碼集錦/2011年/11月/Android 兩點縮放字體/

MultiTouchTestActivity

  1. package src.youer.text;
  2. import java.io.InputStream;
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.TextView;
  6. public class MultiTouchTestActivity extends Activity
  7. {
  8. @Override
  9. public void onCreate(Bundle savedInstanceState)
  10. {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.main);
  13. TextView textView = (TextView) this.findViewById(R.id.text_view);
  14. try
  15. {
  16. textView.setText(readText());
  17. }
  18. catch (Exception e)
  19. {
  20. e.printStackTrace();
  21. }
  22. float zoomScale = 0.5f;// 縮放比例
  23. new ZoomTextView(textView, zoomScale);
  24. }
  25. /**
  26. * 讀取txt
  27. *
  28. * @param str
  29. * @return
  30. * @throws Exception
  31. */
  32. public String readText() throws Exception
  33. {
  34. InputStream is = this.getClass()
  35. .getResourceAsStream("/assets/text.txt");
  36. int index = is.available();
  37. byte data[] = new byte[index];
  38. is.read(data);
  39. return new String(data, "UTF-8");
  40. }
  41. }

ZoomTextView

  1. package src.youer.text;
  2. import android.widget.TextView;
  3. public class ZoomTextView extends ZoomView<TextView>
  4. {
  5. /** 最小字體 */
  6. public static final float MIN_TEXT_SIZE = 10f;
  7. /** 最大子圖 */
  8. public static final float MAX_TEXT_SIZE = 100.0f;
  9. /** 縮放比例 */
  10. float scale;
  11. /** 設置字體大小 */
  12. float textSize;
  13. public ZoomTextView(TextView view, float scale)
  14. {
  15. super(view);
  16. this.scale = scale;
  17. textSize = view.getTextSize();
  18. }
  19. /**
  20. * 放大
  21. */
  22. protected void zoomOut()
  23. {
  24. textSize += scale;
  25. if (textSize > MAX_TEXT_SIZE)
  26. {
  27. textSize = MAX_TEXT_SIZE;
  28. }
  29. view.setTextSize(textSize);
  30. }
  31. /**
  32. * 縮小
  33. */
  34. protected void zoomIn()
  35. {
  36. textSize -= scale;
  37. if (textSize < MIN_TEXT_SIZE)
  38. {
  39. textSize = MIN_TEXT_SIZE;
  40. }
  41. view.setTextSize(textSize);
  42. }
  43. }
Copyright © Linux教程網 All Rights Reserved