Category: 计算机技术

UIImage和CGImage的区别

在iOS中经常碰到二者转换的情况,有啥区别呢,见《iPhone Programming》Chapter 18: UIKit (where we get UIImage    and    anything    else    prefixed    with    UI) only exists on the iPhone. Core Animation, however, exists on the iPhone and on the Mac. This means using the Core Graphics types makes your code portable between systems. Fortunately, UIKit objects have methods to easily switch between themselves and their [...]

星期四 一月 20th, 2011 in 计算机技术 | No Comments »

使用CATextLayer

在对CALayer的最简单使用中使用的是超类CALayer。在该示例上稍作改动,将图片替换为文字: 代码如下: -(void)loadSimpleImageAnimation{     //创建层     CATextLayer *layer = [CATextLayer layer];     layer.string=@"Marshal";     layer.foregroundColor=[[UIColor blackColor] CGColor];             layer.bounds = CGRectMake(0, 0, 200,200);     layer.position = CGPointMake(1024/2 , 768/2);//层在view的位置     [self.view.layer addSublayer:layer];//将层加到当前View的默认layer下         [layer release]; }    发送文章为PDF   

星期三 一月 19th, 2011 in 计算机技术 | No Comments »

对CALayer的最简单使用

iOS的Core Animation,有很多概念,包括Layer(层)、Animation(动画)和Timing(时序)、Layout(布局)和constraint(约束)、Transaction(处理)。其中Layer是最基础的。 本文示例将在层中显示图片,层的背景是黑色的,层被定位在屏幕的中心,可以通过背景辨认出哪部分是由层来实现的。 Layer有多种,最基本的是CALayer,它也是其他种类Layer的父类。CALayer的子类有: CAScrollLayer,用于简化显示层的一部分 CATextLayer,便于从字符串生成内容是文本的层 CATiledLayer,可用于显示复杂的图片 CAOpenGLLayer,提供OpenGLES渲染环境 日志引用使用CATextLayer    发送文章为PDF   

星期三 一月 19th, 2011 in 计算机技术 | No Comments »

使用圆参数方程平均分布图片在圆的周长上

做图形界面开发的感觉是,可以运用到一些数学知识了,哈哈。需求是将若干小图片平均分布在圆的周长上。效果如下: 用右侧图来表示,就是要求x和y的坐标。iPad的坐标系从左上开始。 圆参数方程公式: x=R*cos(A) y=R*sin(A) 日志引用排列和拖动视图    发送文章为PDF   

星期二 一月 18th, 2011 in 计算机技术 | No Comments »

ios自动横屏

如果想让iPad在横屏情况下根据重力感应自动朝上显示,需要在Controller里面修改下面的方法: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 默认是return YES的,这样不论哪个方向都会自动调整屏幕。 如果在iPhone环境下,是取消自动调整屏幕的。 横屏情况下根据重力感应自动朝上显示的代码如下: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {     return (interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation==UIDeviceOrientationLandscapeLeft); }    发送文章为PDF   

星期一 一月 17th, 2011 in 计算机技术 | No Comments »

解决ListView滚动卡的问题

写了个类似下面的GridView,滚动的时候有卡或者跳格的现象,尤其当记录比较多的时候。 GridView和ListView机制原理是类似的,都是基于ListAdapter来处理View的控制的。在排查问题的时候也测试了用ListView替换GridView,问题依旧。 实现的示例大致是这个样子: 日志引用实现类似Android Grid效果的列表视图    发送文章为PDF   

星期五 一月 14th, 2011 in 计算机技术 | 3 Comments »

查看Android进程内存资源信息

在Android下,adb shell进入系统,如果用top来查看信息,不是很直观。直接top,格式很混乱。可: top -m 6 查看前6个进程信息。 android提供了更好的工具,procrank。比如: # procrank   PID      Vss      Rss      Pss      Uss  cmdline   101   82080K   46308K   24907K   21760K  system_server   191   42272K   42268K   21354K   18900K  android.process.acore 1524   39212K   27972K    9343K    8104K  qat.pad.speeed.view 其中vss(virtual set size)是虚拟内存,uss(unique set size)是比较能准确说明进程内存使用情况的。 本文参考: http://elinux.org/Android_Memory_Usage    发送文章为PDF   

星期四 一月 13th, 2011 in 计算机技术 | No Comments »

Dalvik内存调整及监控报告

目前开发android应用,主要问题在内存的使用上,需要熟悉andorid虚拟机Dalvik的内存特性。以下是Nexusone Android 2.2(非官方的CM衍生版)做的实验。 使用系统自带的高级配置功能,不确定官方版本是否有这个选项,似乎是没有。 安装系统后默认的是32M,网上有人说设置12M小的应用启动更快。先设置成最小的12M。 为了测试方便,写了个小应用,就是循环增加内存,测试堆是否可到达12M。 这是运行的报错: 01-13 15:59:05.758: ERROR/dalvikvm-heap(2383): Out of memory on a 1466-byte allocation. 01-13 15:59:05.868: INFO/dalvikvm-heap(2383): Clamp target GC heap from 13.922MB to 12.000MB 01-13 15:59:28.929: ERROR/dalvikvm-heap(200): Heap Massage needed (36000-byte external allocation too big)    发送文章为PDF   

星期四 一月 13th, 2011 in 计算机技术 | No Comments »

ListView快速滚动示例增加首字母提示

在自定义ListView FastScroller滑块图片中实现了快速滚动。在原有示例基础上增加了这样的功能: 本文和上面示例借鉴了: http://blog.csdn.net/sodino/archive/2010/12/15/6077017.aspx 做的比较简单。需要为ListView注册一个滚动监听器: listView.setOnScrollListener(new OnScrollListener() {     boolean visible;     @Override     public void onScrollStateChanged(AbsListView view, int scrollState) {         visible = true;         if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE) {             overlay.setVisibility(View.INVISIBLE);         }     }     @Override     public void onScroll(AbsListView view, int firstVisibleItem,             int visibleItemCount, int totalItemCount) {         if (visible) [...]

星期五 一月 7th, 2011 in 计算机技术 | 4 Comments »

自定义ListView FastScroller滑块图片

使用ListView FastScroller,默认滑块和自定义滑块图片的样子: 设置快速滚动属性很容易,只需在布局的xml文件里设置属性即可: <ListView android:id="@+id/listView" android:layout_width="fill_parent"     android:layout_height="fill_parent" android:fastScrollEnabled="true"     android:focusable="true" /> 但是有时候会发现设置属性无效,滚动ListView并未出现滑块。原因是该属性生效有最小记录限制。当ListView记录能够在4屏以内显示(也就是说滚动4页)就不会出现滑块。可能是api设计者认为这么少的记录不需要快速滚动。 我的依据是android源代码,见FastScroller的常量声明: // Minimum number of pages to justify showing a fast scroll thumb    private static int MIN_PAGES = 4; 日志引用ListView快速滚动示例增加首字母提示    发送文章为PDF   

星期五 一月 7th, 2011 in 计算机技术 | 6 Comments »