public final void setTop (int top)

Sets the top position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

api 文档上说不应该直接执行这个方法,所以setTop即使在api 11以上也是不合理的。这时应该使用setTranslationX)、setTranslationY),也即setX、setY。 那么为了兼容api 11以下而采用的办法是用改变margin的方式来达到改变位置的目的,涉及到三个方法getLayoutParams)、setMarigns)、setLayoutParams) LayoutParams olp=(LayoutParams) box.getLayoutParams(); olp.setMargins(olp2.leftMargin, 0, olp2.rightMargin, olp2.bottomMargin); box.setLayoutParams(olp);

情景:获取json数据后,通过Gson转换成数据模型实例,之前并未implements Parcelable,后来需要在activity里传递这个对象,于是implements了,于是generate constructor using fields,然后就报错“com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@4156b0f8 failed to deserialized json object “ 后来借助万能的bing(中英结果全能,广告少,墙内)发现Gson用的model例子都有个无参的contructor,于是source -> generate constructor from superclass ,问题解决!

嗯,下面是从网上摘录过来的,之前我也是用这种方法引入过一个library,后来又在一个项目用这种方法引入,所以也轻车熟路了。在几次在两台电脑移动项目来开发后就遇到了问题,在主project Properties->android ->library add 我需要的library后当时是绿勾 点击ok后我再点击properties发现绿勾变成了红叉。我还尝试点击fix 提示我将这个project加入到buid path,点击后java buid path 里就多了这个Project然而真正运行时还是class not found,事实是我的主project是import过来,没有勾选copy to workspace结果就产生这种问题。随后我删除了重新Import然后勾选copy to workspace,嗯,接下来的问题两个project都有android-support-v4.jar,然后其他的class name就can’t resovled了,于是把其中一个复制粘贴覆盖另一个就OK了。 Referencing a library project If you are developing an application and want to include the shared code or resources from a library project, you can do so easily by adding a reference to the library project in the application project’s Properties. To add a reference to a library project, follow these steps:

  1. In the Package Explorer, right-click the dependent project and select Properties.
  2. In the Properties window, select the “Android“ properties group at left and locate the Library properties at right.
  3. Click Add to open the Project Selection dialog.
  4. From the list of available library projects, select a project and click OK.
  5. When the dialog closes, click Apply in the Properties window.
  6. Click OK to close the Properties window.

As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project. Figure 2 shows the Properties dialog that lets you add library references and move them up and down in priority. 111006095062621 Figure 2. Adding a reference to a library project in the properties of an application project. If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by selecting a library and using the Up and Down controls. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.

Declaring library components in the the manifest file

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any , , , , and so on, as well as, , and similar elements. Declarations should reference the library components by their fully-qualified package names, where appropriate. For example, the TicTacToeMain example application declares the library Activity GameActivity like this:

… … …

定位 SDK>Android 定位SDK>开发指南 最开始我按照文档在Application 里new LocationClient ,然后start。在Application里implements BDLocationListener , mLocationClient.registerLocationListener( myListener ).经过两个activity跳转我在onCreate里locationClient.requestLocation();我以为已经可以得到了位置了,准备发起一个网络请求根据经纬度获取一些信息。getLastKnownLocation()之前一直都好好的,后来就一直不行,经过不断的各种调整(大概都不在重点上)时而能正常获得数据,我把时间都花在搜索“No JNI_OnLoad found in”,大多数都是某某写了个c库,遇到这个问题,很显然不适合我现在的情况,最后我在stackoverflow看到这篇no-jni-onload-found-in-skipping-init原来“No JNI_OnLoad found in”根本不是问题所在。后来我在发起网络请求前加了判断

if (locationClient == null)
        return;
    BDLocation lastLocation = locationClient.getLastKnownLocation();
    if (locationClient.isStarted() == false )
    { Log.d(tag, "locClient isStarted ==false");
        ;}
    if(lastLocation==null){
        Log.d(tag, "lastLocation is null ");
        return;
    }

发现这里的log信息总会出来,后来我把Application里registerLocationListener给注释掉了,把BDLocationListener 换成在Activity里实现,在onReceiveLocation里通过获取到的位置发起请求问题解决了。 下面还有一些收集的资料 “at com.baidu.location.LocationClient.a(Unknown Source) ” 是因为没有注册Receiver: mLocClient.registerLocationListener(myListener); locSdk每次定位都会调用application的oncreate方法 只有调用mLocClient.start()才会调用到Application的onCreate, 是因为定位本身用到了sevice,而service的oncreate,会导致调用application的 oncreate方法。至于mLocClient.requestLocation();这个不算是重新启动service 所以不会是application再次调用。 这个属于android的机制,这个没办法修正的。你可以设置个值,来控制一下初始化的问题。

<!-- .test .sb{width: 60px;height: 28px; /*background-image: url(http://static.wumii.cn/images/blogWidget/widget\_buttons\_deepBlue.png) ; if the border attribute isn’t defined,this image will not display*/ cursor: pointer; outline: none; background-repeat: no-repeat no-repeat; } .test .sb1{background: url(http://static.wumii.cn/images/blogWidget/widget\_buttons\_deepBlue.png); background-position: -267px 0px;border: none;/*more efficient*/ /*border: 0;works*/ /*border:; works but has border*/ } .test .sb2{background-image: url(http://static.wumii.cn/images/blogWidget/widget\_buttons\_deepBlue.png);background-position: -267px 0px;} –>

下面是测试input

上面是测试input

emojimenu emoji-menu emojimenu选择表情后输入框里是表情代号,图片也是按照代号来命名的 Unified Emoji表情for Android 这位达达把图片都按UTF8编码的形式来命名,输入框也是基于emojimenu所以也是输入代号。 试用了下图片包不全我是把表情的命名写在arrays.xml里了。这样使用方便,然后选择表情输入框里是添加表情,剩下的工作就是发送的时候把表情转换成相应的字符,把收到的聊天信息里解析出表情显示在聊天对话框里。

unicode-emoji (unicode6 ios6版的图片表情包) 2013年的项目 比较全,也是按编码来命名的

另外贴上供参考: ios emoji table (ios5) ios emoji table (ios6) Emoji表情图标在iOS与PHP之间通信及MySQL存储

嗯 事实上是可行的 只是不能直接用asset里的apk来安装,大概搜索了好几个小时,最终把问题解决。 试用过的方法都写在@deprecated里了。 解析错误 解析包时出现问题 Android - failed to open zip archive Programatically install apk from assets folder in android

@Deprecated
private void install\_voice\_search() {
    String apkPath = "file:///android_asset/";
    String destapkName = "com.google.android.voicesearch.apk";
    File file = null;
    file = new File(apkPath, destapkName);
    try {

        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream os = openFileOutput(file.getName(),
                Context.MODE\_WORLD\_READABLE);
        InputStream is = null;
        byte\[\] bytes = new byte\[512\];
        int i = -1;
        while ((i = is.read(bytes)) > 0) {
            os.write(bytes);
        }

        os.close();
        is.close();
        String permission = "666";

        try {

            String command = "chmod " + permission + " " + apkPath + "/"
                    \+ destapkName;
            Runtime runtime = Runtime.getRuntime();
            runtime.exec(command);
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        Log.e("----", e.toString());
    }

    if (file != null) {
        Intent intentInstall = new Intent();
        intentInstall.setAction(android.content.Intent.ACTION_VIEW);
        intentInstall.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
        intentInstall.setFlags(Intent.FLAG\_ACTIVITY\_NEW_TASK);
        startActivity(intentInstall);
    }
}

@Deprecated
private void install3() {
    Intent intentInstall = new Intent();
    intentInstall.setAction(android.content.Intent.ACTION_VIEW);
    intentInstall.setDataAndType(Uri.fromFile(new File(
            "file:///android_asset/com.google.android.voicesearch.apk")),
            "application/vnd.android.package-archive");
    intentInstall.setFlags(Intent.FLAG\_ACTIVITY\_NEW_TASK);
    startActivity(intentInstall);
}

private void finalinstall() {
    AssetManager assetManager = getAssets();

    InputStream in = null;
    OutputStream out = null;

    try {
        in = assetManager.open("com.google.android.voicesearch.apk");
        Log.i(tag, Environment.getExternalStorageDirectory().getPath());
        out = new FileOutputStream(Environment
                .getExternalStorageDirectory().getPath()
                \+ "/com.google.android.voicesearch.apk");

        byte\[\] buffer = new byte\[1024\];

        int read;
        while ((read = in.read(buffer)) != -1) {

            out.write(buffer, 0, read);

        }

        in.close();
        in = null;

        out.flush();
        out.close();
        out = null;

        Intent intent = new Intent(Intent.ACTION_VIEW);

        intent.setDataAndType(Uri.fromFile(new File(Environment
                .getExternalStorageDirectory().getPath()
                \+ "/com.google.android.voicesearch.apk")),
                "application/vnd.android.package-archive");

        startActivity(intent);

    } catch (Exception e) {
    }
}

class SQLAlchemy(object):
“””實例並初始化:
app = Flask(__name__)
db = SQLAlchemy(app)
先實例化,再初始化
db = SQLAlchemy()”””
def __init__(self, app=None,
use_native_unicode=True,
session_options=None):
“””……”””
self.Model = self.make_declarative_base() “””Creates the declarative base.”””
“””…….”””
self.Query = BaseQuery
“”“……”“”
def make_declarative_base(self):
“””Creates the declarative base.”””
base = declarative_base(cls=Model, name=’Model’,
metaclass=_BoundDeclarativeMeta)
base.query = _QueryProperty(self)
return base

class QueryProperty(object):
“””return The Query Object”””
def \
_init__(self, sa):”””sa an instance of SQLAlchemy class”””
self.sa = sa

def \_\_get\_\_(self, obj, type):
  try:
      """sqlalchemy.orm.class\_mapper(class\_, compile=True)
          Given a class, return the primary Mapper associated with the key.
      """
      mapper = orm.class_mapper(type)
      if mapper:
          """query_class=BaseQuery inherit of sqlalchemy.orm.query.Query,
          class sqlalchemy.orm.query.Query(entities, session=None)"""
          return type.query_class(mapper, session=self.sa.session())
  except UnmappedClassError:
      return None

class Model(object):
“””Baseclass for custom user models.”””

#: the query class used.  The :attr:\`query\` attribute is an instance
#: of this class.  By default a :class:\`BaseQuery\` is used.
query_class = BaseQuery

#: an instance of :attr:\`query_class\`.  Can be used to query the
#: database for instances of this model.
query = None

class BaseQuery(orm.Query):
“””繼承sqlalchemy.orm.query.Query,@see http://docs.sqlalchemy.org/en/rel\_0\_9/orm/query.html"""

历史:

如果我没记错的话,script defer 最开始是IE提出,其他浏览器厂商随后跟进提供支持。

用法:

defer用来声明该脚本不包含document.write 以使浏览器可以异步的加载(异步加载不是关键,其实最重要的是不阻塞html的解析,这也就是为什么脚本里不能含有document.write),然后按照声明defer的script标签的顺序来执行(这是与async标签的不同)。 需要记住的是,标明defer的script 必须是个外部引入的脚本而不能是inline script。 @see http://dev.w3.org/html5/spec/scripting-1.html#attr-script-defer

The defer and async attributes must not be specified if the src attribute is not present.

兼容性:

mozilla 开发人员中心 提到:

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) (Yes) (Yes) (Yes)
async attribute (Yes) 3.6 (1.9.2) 10 Not supported (Yes)
defer attribute (Yes) 3.5 (1.9.1) 4 (follows a spec of its own) Not supported (Yes)
10 (by the spec)

Chrome                            Firefox(Gecko)       Internet Explorer   Opera        Safari

crossorigin attribute 30.0 Chromium Bug 159566 13.0 (13) bug 696301 Not supported 12.50 (Yes)
(WebKit bug 81438)

@see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script?redirectlocale=en-US&redirectslug=HTML%2FElement%2Fscript 尽管上面提到IE 从IE4开始支持defer,但它遵循的是IE自家的定义,从10才开始按照规范。 Internet Explorer 5.1.7 Mac下的bug. http://www.websiteoptimization.com/speed/tweak/defer/test/“ target=”_blank”>Internet Explorer 5.1.7 Mac shows sequential execution despite the defer attribute stackoverflow 上有提到:

defer works with chrome , firefox , ie > 7 and Safari

@see http://stackoverflow.com/questions/5250412/how-exactly-does-script-defer-defer-work 当然PO主犯了个严重的错误,在inline script 用defer属性。 然而问题还没有完, https://github.com/h5bp/lazyweb-requests/issues/42#issuecomment-1901803

And the first script modifies the dom with appendChild, innerHTML, (etc.), the second script can start executing before the first one has finished. Thus, a dependency between the two will break.

我看了上面这个issues两遍(E文实在糟糕),这个问题我自己还没遇到过,之前我都是jquery直接在head里加载完,剩下的jquery 插件才加defer,主要是我不会在dom ready之前去改变文档的结构。

去年我寻找一款类似Digg的开源软件,找到Pligg,然后试安装一下,期间遇到安装问题,解决办法见Pligg安装使用教程。近期我又开始捣腾它,经过去年的折磨实在不太想碰它,没办法,想做一个类似Digg的想法比较强烈。Pligg没有使用时下流行的MVC设计模式,没有统一入口,意味着脚本分散开来做获取数据,渲染模板等工作。(现在官方网站提供的下载是1.2.2,最新的2.0.0 (beta)版售价10美元 采用Smarty做模板引擎,我本身也不太熟悉,语法在编辑器(Sublime)里没有高亮比较蛋疼。Pligg的基础模板是pligg.tpl,其他都是分块载入。模板里的Smarty实例是$templatelite,意味着用Smarty的section遍历时可以用$templatelite.section.thistag.iteration获得数组下标。 下面我列几个我在开发中发现的问题: link_summary.tpl 用到libs/link.php里的 get_group_membered,而且link_summary模板实际上是一个放在循环里的子模板,也就是在一个列表页每一项link的summary里都会隐藏用户已加入的群组,以便在点击分享到群组时弹出,无疑增加html的大小,把get_group_membered放在link类里,逻辑上也不合理,所以我把此方法移至libs/smartyvariable 并asign一个变量以在模板里获取群组列表。 用户可能有加入群组也可能一个都没有,这个逻辑判断我加在pligg.tpl里的一个script标签(javascript template)里然后在{literal} script里绑定相关事件获取javascript template里的内容。 在link_summary.tpl的代码里还体现出了pligg的开发团队的前端实在不忍直视,save link或者remove link的标签id都是linksummarySaveLink,随后我改成了class,这实在是个非常低级的错误。还有一种操作也是类似情况。另一个我无法忍受的是这些操作居然target是提交到一个Iframe,save link一个iframe,remove link一个iframe,而iframe的name居然是一样的。我又把这些操作用class分别开来,在用jquery绑定事件,由于我自己偷懒没有在事件处理里获取要操作的html元素,把它的onclick写成了data-callback,然后直接eval了。 再说说pligg的i18n,Pligg默认的语言包出了english后缀都加了.default,于是如果在后台换成其他语言的话是找不到语言包的,而后台有一项allow users select language我启用后始终没发现,选择语言的界面元素在哪,而根据我查看php代码发现是没有这样的机制的。其实我们可以在config.php里获取HTTP_ACCEPT_LANGUAGE然后根据数组映射加载相应的语言文件,界面上添加一个选择语言,随后设置cookie根据cookie来加载相应的语言包文件也是可以的。 用户提交链接时submit.php // if (!$_COOKIE['referrer']) // check_referrer();没有任何地方set过cookie referer,提交的时候你来检查有意思吗?即便设置过你检查referrer不是本站就直接拒绝,那提供的js书签栏工具有何意义? 嗯,于是我删除了。

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×