当前位置: 编程技术>移动开发
本页文章导读:
▪创办SurfaceView的最佳位置 创建SurfaceView的最佳位置
我在网上看了许多大牛创建SurfaceView的位置都是在Activty的onCreate()中进行的,本人最近一直在做Android视频这一块,用的SurfaceView来显示视频数据。如果在Activty的onCre.........
▪ QQ阅读器技术框架解析之二《代码预览跟分析》 QQ阅读器技术框架解析之二《代码预览和分析》
本文主要分析书架模块的原理和模型书架的整体分为书架、书城、账户,统一到一个Activity为:MainActivity,继承TabActivity
public class MainActivity .........
▪ struts2 标签使用错误 The Struts dispatcher cannot be found struts2 标签使用异常 The Struts dispatcher cannot be found
struts2 标签使用异常 The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the .........
[1]创办SurfaceView的最佳位置
来源: 互联网 发布时间: 2014-02-18
创建SurfaceView的最佳位置
我在网上看了许多大牛创建SurfaceView的位置都是在Activty的onCreate()中进行的,本人最近一直在做Android视频这一块,用的SurfaceView来显示视频数据。如果在Activty的
onCreate()中创建SurfaceView会遇到一些莫名奇妙的问题。
为了方便起见,我给大家写个测试,来说明问题的原因
在onCreate()中创建SurfaceView的效果图如下:
代码:
原因是你在短按Home键时,程序后台运行,SurfaceView的surfaceDestroyed()方法执行了,此时销毁画图线程。所以你再次进入这个界面时,由于SurcefaceView未创建,画图线
程未启动,所以看不到任何图像。那怎样解决这个问题?
借助Activity生命周期,重写onResume()方法。
我在网上看了许多大牛创建SurfaceView的位置都是在Activty的onCreate()中进行的,本人最近一直在做Android视频这一块,用的SurfaceView来显示视频数据。如果在Activty的
onCreate()中创建SurfaceView会遇到一些莫名奇妙的问题。
为了方便起见,我给大家写个测试,来说明问题的原因
在onCreate()中创建SurfaceView的效果图如下:
代码:
package com.t1; import android.app.Activity; import android.os.Bundle; import android.view.SurfaceView; public class T1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SurfaceView mv = new T3(this); setContentView(mv); } }
package com.t1; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Paint.Style; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.SurfaceHolder.Callback; public class T3 extends SurfaceView implements Runnable, Callback { private SurfaceHolder mHolder; // 用于控制SurfaceView private Thread t; // 声明一条线程 private volatile boolean flag; // 线程运行的标识,用于控制线程 private Canvas mCanvas; // 声明一张画布 private Paint p; // 声明一支画笔 float m_circle_r = 10; public T3(Context context) { super(context); mHolder = getHolder(); // 获得SurfaceHolder对象 mHolder.addCallback(this); // 为SurfaceView添加状态监听 p = new Paint(); // 创建一个画笔对象 p.setColor(Color.WHITE); // 设置画笔的颜色为白色 setFocusable(true); // 设置焦点 } /** * 当SurfaceView创建的时候,调用此函数 */ @Override public void surfaceCreated(SurfaceHolder holder) { //if(t == null) { t = new Thread(this); // 创建一个线程对象 flag = true; // 把线程运行的标识设置成true t.start(); // 启动线程 //} } /** * 当SurfaceView的视图发生改变的时候,调用此函数 */ @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } /** * 当SurfaceView销毁的时候,调用此函数 */ @Override public void surfaceDestroyed(SurfaceHolder holder) { mHolder.removeCallback(this); flag = false; } @Override public void run() { while (flag) { try { synchronized (mHolder) { Thread.sleep(100); // 让线程休息100毫秒 draw(); // 调用自定义画画方法 } } catch (InterruptedException e) { e.printStackTrace(); } finally { if (mCanvas != null) { // mHolder.unlockCanvasAndPost(mCanvas);//结束锁定画图,并提交改变。 } } } } private void draw() { mCanvas = mHolder.lockCanvas(); if (mCanvas != null) { mCanvas.drawColor(Color.TRANSPARENT,PorterDuff.Mode.CLEAR); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED); paint.setStrokeWidth(10); paint.setStyle(Style.FILL); if (m_circle_r >= (getWidth() / 10)) { m_circle_r = 0; } else { m_circle_r++; } for (int i = 0; i < 5; i++) for (int j = 0; j < 8; j++) mCanvas.drawCircle( (getWidth() / 5) * i + (getWidth() / 10), (getHeight() / 8) * j + (getHeight() / 16), m_circle_r, paint); mHolder.unlockCanvasAndPost(mCanvas); } } }
原因是你在短按Home键时,程序后台运行,SurfaceView的surfaceDestroyed()方法执行了,此时销毁画图线程。所以你再次进入这个界面时,由于SurcefaceView未创建,画图线
程未启动,所以看不到任何图像。那怎样解决这个问题?
借助Activity生命周期,重写onResume()方法。
public class T1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override protected void onResume() { super.onResume(); SurfaceView mv = new T3(this); setContentView(mv); } }运行效果图如下,完美解决。
[2] QQ阅读器技术框架解析之二《代码预览跟分析》
来源: 互联网 发布时间: 2014-02-18
QQ阅读器技术框架解析之二《代码预览和分析》
本文主要分析书架模块的原理和模型
书架的整体分为书架、书城、账户,统一到一个Activity为:MainActivity,继承TabActivity
书架的整体布局是TabHost,布局文件为maintabs.xml,整体分布如图
本文主要介绍书架的架构
入口函数:onCreate
1. 设置notitle(这个可以放到activity的配置文件中)
2. 设置layout为new_bookstand.xml:顶部阴影,两侧图片中间是自定的listview:com.qq.reader.view.SpringListView.java,这个list是可以支持整体滑动效果的,从1.0版本到现在始终是这个listview。
3. 初始化listview的适配器
1. 获取屏幕宽度,除以每本所占的宽度,计算每行可以展示书本个数cols,这样解决了多种屏幕展示的问题
2. 获取屏幕高度,除以每行书架所占的高度,计算每屏幕可以展示的书架行数rows,书架最小行数为cols+1;
3. getCount即list的行数等于:(书本总个数 + 1)除以每行展示的个数;
4. getView,单个视图为new_liner_item.xml,它其实是个linearLayout,用于存放单个书本的view,本质上是每行的容器,其中设置了背景等基本排版信息。
1. 生成每本书的layout对象bookmarkstanditem.xml,渲染模板后,添加到父容器linearLayout中。直到填满每行展示的书本个数。
2. 如果父容器已经存在,则便利父容器的子视图对象,逐一渲染
5. getItem/getItemId,大家都懂得。
6. listview添加了header,本质是textView,就是书架上方的广告栏,支持点击事件
7. 书本的点击函数在哪里?
1. 不可在listview上添加点击,因为书本知识listview每行中的一本,点击事件只能添加到每本书的布局视图上
2. QQ的点击事件在书本视图的最外层RelativeLayout上,并把当前书本的id放在tag中,当点击书本时,点击函数从getItem传入tag,获取书本对象,打开书本。
8. 书本的长按函数在哪里?
1. 同样也在layout上,长按函数本质是图案出一个对话框,根据layout的tag中的书本id获取书本对象后,渲染dialog的内容。
9. 书架左侧书本分类与广告都在listview的head视图中(standlist_header.xml)
1. 本质也是对话框,通过设置进入和退出动画,给人的感觉是好像从书架延伸出来的一样。
2. 点击分类名的核心代码
首先设置listview的当前选择项为0,然后展示对话框
10. 书架下侧的本地文件浏览窗口
1. 实现方式:SlidingDrawer(滑动抽屉)
2. 抽屉分为抽屉句柄和抽屉内部内容,点击句柄“本地”按钮,设置动画显示抽屉的内容,点击“返回”隐藏抽屉的内容
本文主要分析书架模块的原理和模型
书架的整体分为书架、书城、账户,统一到一个Activity为:MainActivity,继承TabActivity
public class MainActivity extends TabActivity implements CompoundButton.OnCheckedChangeListener, cu, m
书架的整体布局是TabHost,布局文件为maintabs.xml,整体分布如图
分别对应 书架:BookStandActivity.java 书城:WebBrowser.java 账户:ProfileActivity.java 本地:点击出现本地文件浏览窗口
本文主要介绍书架的架构
BookStandActivity extends ReaderBaseActivity implements DialogInterface.OnCancelListener, View.OnCreateContextMenuListener
入口函数:onCreate
1. 设置notitle(这个可以放到activity的配置文件中)
2. 设置layout为new_bookstand.xml:顶部阴影,两侧图片中间是自定的listview:com.qq.reader.view.SpringListView.java,这个list是可以支持整体滑动效果的,从1.0版本到现在始终是这个listview。
3. 初始化listview的适配器
1. 获取屏幕宽度,除以每本所占的宽度,计算每行可以展示书本个数cols,这样解决了多种屏幕展示的问题
2. 获取屏幕高度,除以每行书架所占的高度,计算每屏幕可以展示的书架行数rows,书架最小行数为cols+1;
3. getCount即list的行数等于:(书本总个数 + 1)除以每行展示的个数;
4. getView,单个视图为new_liner_item.xml,它其实是个linearLayout,用于存放单个书本的view,本质上是每行的容器,其中设置了背景等基本排版信息。
1. 生成每本书的layout对象bookmarkstanditem.xml,渲染模板后,添加到父容器linearLayout中。直到填满每行展示的书本个数。
2. 如果父容器已经存在,则便利父容器的子视图对象,逐一渲染
5. getItem/getItemId,大家都懂得。
6. listview添加了header,本质是textView,就是书架上方的广告栏,支持点击事件
7. 书本的点击函数在哪里?
1. 不可在listview上添加点击,因为书本知识listview每行中的一本,点击事件只能添加到每本书的布局视图上
2. QQ的点击事件在书本视图的最外层RelativeLayout上,并把当前书本的id放在tag中,当点击书本时,点击函数从getItem传入tag,获取书本对象,打开书本。
8. 书本的长按函数在哪里?
1. 同样也在layout上,长按函数本质是图案出一个对话框,根据layout的tag中的书本id获取书本对象后,渲染dialog的内容。
9. 书架左侧书本分类与广告都在listview的head视图中(standlist_header.xml)
1. 本质也是对话框,通过设置进入和退出动画,给人的感觉是好像从书架延伸出来的一样。
2. 点击分类名的核心代码
@Override public final void onClick(View paramView) { ((ListView) BookStandActivity.j(this.a)).setSelection(0); BookStandActivity.b(this.a, false); a.a(13, 0); }
首先设置listview的当前选择项为0,然后展示对话框
10. 书架下侧的本地文件浏览窗口
1. 实现方式:SlidingDrawer(滑动抽屉)
public class SlidingDrawerFileBrowser extends SlidingDrawer implements View.OnCreateContextMenuListener, AbsListView.OnScrollListener
2. 抽屉分为抽屉句柄和抽屉内部内容,点击句柄“本地”按钮,设置动画显示抽屉的内容,点击“返回”隐藏抽屉的内容
[3] struts2 标签使用错误 The Struts dispatcher cannot be found
来源: 互联网 发布时间: 2014-02-18
struts2 标签使用异常 The Struts dispatcher cannot be found
struts2 标签使用异常 The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
在JSP 使用struts2标签报错。。
总结后是 web.xml 的配置错误。。
原来的
<!-- struts2 图片上传 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
修改后。。需要为 .jsp 配置
<!-- struts2 图片上传 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
重新启动。OK
I am moving from other Servers like glassfishv2,tomcat6 to jrun4.
When i practice the tutorial from this link: http://struts.apache.org/2.0.11.1/docs/struts-2-spring-2-jpa-ajax.html
I've got a The Struts dispatcher cannot be found error, even though I successfully run this project on Tomcat6 and glassfishv2.
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBody TagSupport.java:52)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(Component TagSupport.java:49)
at jrun__index2ejspa._jspService(jrun__index2ejspa.java:56)
at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
at jrun.jsp.JSPServlet.service(JSPServlet.java:119)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invokeNext(JRunRequestDispatcher.j ava:586)
at jrun.servlet.JRunRequestDispatcher.forwardInvoke(JRunRequestDispatche r.java:555)
at jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java :203)
at jrun.servlet.file.FileServlet.service(FileServlet.java:316)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java: 286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java: 543)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.j ava:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
The web.xml is put under WEB-INF. Its content is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="person" version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>person</display-name>
<!-- Include this if you are using Hibernate -->
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter- class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
struts2 标签使用异常 The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
在JSP 使用struts2标签报错。。
总结后是 web.xml 的配置错误。。
原来的
<!-- struts2 图片上传 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
修改后。。需要为 .jsp 配置
<!-- struts2 图片上传 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
重新启动。OK
I am moving from other Servers like glassfishv2,tomcat6 to jrun4.
When i practice the tutorial from this link: http://struts.apache.org/2.0.11.1/docs/struts-2-spring-2-jpa-ajax.html
I've got a The Struts dispatcher cannot be found error, even though I successfully run this project on Tomcat6 and glassfishv2.
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBody TagSupport.java:52)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(Component TagSupport.java:49)
at jrun__index2ejspa._jspService(jrun__index2ejspa.java:56)
at jrun.jsp.runtime.HttpJSPServlet.service(HttpJSPServlet.java:43)
at jrun.jsp.JSPServlet.service(JSPServlet.java:119)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invokeNext(JRunRequestDispatcher.j ava:586)
at jrun.servlet.JRunRequestDispatcher.forwardInvoke(JRunRequestDispatche r.java:555)
at jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java :203)
at jrun.servlet.file.FileServlet.service(FileServlet.java:316)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java: 286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java: 543)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.j ava:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
The web.xml is put under WEB-INF. Its content is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="person" version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>person</display-name>
<!-- Include this if you are using Hibernate -->
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter- class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
最新技术文章: