widget股票分享
前些天无意间搜索android widget 看到了it168的关于android widget 设计大赛,然后自己去找了些关于ANDROID WIDGET 的设计资料,真是太少了,国内差不多就是三个版本,差不多没有撒区别,建立第一个DEMO真的有点麻烦,各位前辈别拍砖头呢,这里写些关于ANDROID widget的设计心得。

项目配置文件目录
项目中使用的关于读入 股票走势图的类
这个类从网络上读取图片的内容 然后返回一个BITMAP,下面有一个Image SCALE 方法,对BITMAP的大小进行处理。
1. package org.allove.widget;
2.
3. import java.io.BufferedInputStream;
4. import java.io.IOException;
5. import java.net.URL;
6. import java.net.URLConnection;
7.
8. import android.graphics.Bitmap;
9. import android.graphics.BitmapFactory;
10. import android.graphics.Matrix;
11. import android.util.Log;
12.
13. public class ImageDownload {
14.
15. public static Bitmap getRemoteImage(final String urlString) {
16. try {
17. URL aURL = new URL(urlString);
18. final URLConnection conn = aURL.openConnection();
19. conn.connect();
20. final BufferedInputStream bis = new BufferedInputStream(conn
21. .getInputStream());
22. final Bitmap bm = BitmapFactory.decodeStream(bis);
23. bis.close();
24.
25. return bm;
26. } catch (IOException e) {
27. Log.d(”DEBUGTAG”, “Oh an error…”);
28. }
29. return null;
30. }
31. public static Bitmap scaleBitmap(Bitmap bitmap){
32.
33.
34. int width = bitmap.getWidth();
35. int height = bitmap.getHeight();
36. int newWidth = 125;
37. int newHeight = 30;
38.
39. // calculate the scale - in this case = 0.4f
40. float scaleWidth = ((float) newWidth) / width;
41. float scaleHeight = ((float) newHeight) / height;
42.
43. // createa matrix for the manipulation
44. Matrix matrix = new Matrix();
45. // resize the bit map
46. matrix.postScale(scaleWidth, scaleHeight);
47. // rotate the Bitmap
48. matrix.postRotate(45);
49.
50. // recreate the new Bitmap
51. return Bitmap.createBitmap(bitmap, 0, 0,
52. width, height, matrix, true);
53. }
54. }
复制代码
WIDGET 中的 xml 配置文件的参数设置问题
xml参数与 代码中的一个AppWidgetProviderInfo中的内容是匹配的
AppwidgetProviderInfo
1. < ?xml version="1.0" encoding="utf-8"?>
2.
3. android:minWidth="240dp"
4. android:minHeight="300dp"
5. android:updatePeriodMillis="60000"
6. android:initialLayout="@layout/appwidget_provider"
7. android:configure="org.allove.widget.WidgetConfiger"
8. >
9.
复制代码
android:updatePeriodMillis=”60000″ 更新数据的时间
minwidth
minheight 配置界面
热度文章