DFdou's Blog Life is short,Be yourself.

3012/090

Android-ImageView setAlpha()的问题

不知道大家有没碰到这种情况,使用同一个图片资源做背景的ImageView,使用setAlpha之后,全部使用该图片资源的ImageView都会被影响到,导致这个问题的原因和解决方案如下:http://android-developers.blogspot.com/2009/05/drawable-mutations.html (PS:被和谐,需要爬墙。)
来个例子说明下,我们需要生成10个ImageView,偶数位的ImageView设置alpha,代码如下:

private int res_ico = R.drawable.icon;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LinearLayout l= (LinearLayout)findViewById(R.id.layout1);
    for(int i=0;i < 10;i++){

        ImageView iv = new ImageView(this);
        iv.setImageResource(res_ico);
        iv.setClickable(false);

        iv.setAdjustViewBounds(true);
        if(i%2==0){
            ico.setAlpha(125);
        }
        l.addView(iv);
    }
}

这样的话就会发现,所有的ImageView的透明度是和最后设置的值一样的,具体原因在上边的网页里有说明,因为大家用的都是一个资源嘛。
那么怎么解决这个问题呢?
方案如下:

private int res_ico = R.drawable.icon;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LinearLayout l= (LinearLayout)findViewById(R.id.layout1);
    for(int i=0;i < 10;i++){
        Drawable ico = getResources().getDrawable(res_ico);
        ImageView iv = new ImageView(this);
        iv.setBackgroundDrawable(ico);
        iv.setClickable(false);

        iv.setAdjustViewBounds(true);
        if(i%2==0){
            ico.mutate().setAlpha(125);
        }
        l.addView(iv);
    }
}

mutate()方法是让图片资源mutable,内部工作原理应该就是克隆了一份自己。
另外:

Drawable ico = getResources().getDrawable(res_ico);

要放在循环里,放在循环体外的话照样会出问题,囧。

2812/091

Android-G3的OOXX

1.关于重启
同时按 通话键+menu+挂断键。
类似于电脑的Ctrl+Alt+Del,还蛮搞的一个设置。
2.关于Gmail帐号的更换。
进入设置-》应用程序-》管理应用程序。清除掉Gmail,Gmail 存储里的数据,然后重启手机,就可以重新设置了,不需要恢复出厂设置。
如果您老用的是英文系统,自己对照翻译吧~
3.关机
按挂机键点亮屏幕后再长按挂机键同时按MENU键会出关机选择菜单。

Tagged as: 1 Comment
2512/092

WordPress-获取指定分类下的标签

函数体:

    function get_category_tags($args) {
        global $wpdb;
        $tags = $wpdb->get_results
        ("
            SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
            FROM
                wp_posts as p1
                LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
                LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
                LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,

                wp_posts as p2
                LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
                LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
                LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
            WHERE
                t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
                t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
                AND p1.ID = p2.ID
            ORDER by tag_name
        ");
        $count = 0;
        foreach ($tags as $tag) {
            $tags[$count]->tag_link = get_tag_link($tag->tag_id);
            $count++;
        }
        return $tags;
    }

wp_是表前缀,看需要改吧。
下边是调用方法:

$args = array('categories' => '12,13,14');
$tags = get_category_tags($args);
Tagged as: , 2 Comments
2312/092

Android-ListView用法

先是在XML里定义一个ListView:

< ?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	>
<listview android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/list"
          />
</linearlayout>

然后呢就在Activity里:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView list = (ListView) findViewById(R.id.list);

    //获得数据,也可以从数据库里读取
    ArrayList<hashmap <String, Object>> listItems = new ArrayList</hashmap><hashmap <String, Object>>();
    for(int i=0;i < 5;i++){
        HashMap<String, Object> map = new HashMap<string , Object>();
        map.put("ItemTitle", "Title "+i);
        map.put("ItemText", "Text "+i);
        listItems.add(map);
    }
    //生成适配器并和动态数组对应的元素绑定
    SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItems,
        R.layout.list_item,
        new String[] {"ItemTitle","ItemText"},
        new int[] {R.id.ItemTitle,R.id.ItemText}
    );

    //设置数据源
    list.setListAdapter(listItemAdapter);

    //点击事件
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView< ?> arg0, View arg1, int arg2,
                long arg3) {
            //do something
        }
	});
}

最后是list_item.xml:

< ?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content">
<textview android:text="Title"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/ItemTitle"
    />
<textview android:text="Text"
	android:layout_height="wrap_content"
	android:layout_width="fill_parent"
	android:id="@+id/ItemText"
	/>
</linearlayout>

可以自己定义list里边各item的样式,加上各种Layout组合就可以做出各种不一样的ListView了。

Tagged as: 2 Comments
2212/090

CSS-区分IE6,IE7,Firefox Hack

以下内容来自http://www.div-css.com/html/XHTML-CSS/hack/1136667.html

区别IE6与FF:
background:orange;*background:blue;

区别IE6与IE7:
background:green !important;background:blue;

区别IE7与FF:
background:orange; *background:green;

区别FF,IE7,IE6:
background:orange;*background:green !important;*background:blue;
注:IE都能识别*;标准浏览器(如FF)不能识别*;

IE6能识别*,但不能识别 !important,
IE7能识别*,也能识别!important;
FF不能识别*,但能识别!important;

另外再补充一个,下划线"_",
IE6支持下划线,IE7和firefox均不支持下划线。

于是大家还可以这样来区分IE6,IE7,firefox:
background:orange;
*background:green;
_background:blue;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。

Tagged as: , No Comments
2112/090

Js-复制到粘贴板

兼容FF和IE:

<script type="text/javascript">
function copyToClipboard(txt) {
	if(window.clipboardData) {
		 window.clipboardData.clearData();
		 window.clipboardData.setData("Text", txt);
	} else if(navigator.userAgent.indexOf("Opera") != -1) {
	  window.location = txt;
	} else if (window.netscape) {
	  try {
		   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	 } catch (e) {
		  alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
	 }
	 var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
	 if (!clip)
		  return;
	 var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
	 if (!trans)
		  return;
	 trans.addDataFlavor('text/unicode');
	 var str = new Object();
	 var len = new Object();
	 var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	 var copytext = txt;
	 str.data = copytext;
	 trans.setTransferData("text/unicode",str,copytext.length*2);
	 var clipid = Components.interfaces.nsIClipboard;
	 if (!clip)
		  return false;
	 clip.setData(trans,null,clipid.kGlobalClipboard);
	 alert("复制成功!")
	}
}
</script>
1712/090

WordPress – Gadgetizer Theme Released

来自http://designdisease.com的主题总是很精致,这次带来的是Gadgetizer Theme:

Gadgetizer

点击查看在线Demo
下边是来自官方那个的介绍:

Gadgetizer is exactly what it sounds like it would be about. Gadgets. We wanted a simple theme that focused on the products themselves, so we have a big Flickr area in the footer section, as well as a mashup of images right below the featured post. As always, the front page has an easy to use “feature” section so you can easily put on display your most in-depth posts. You can even slot in a nice picture and a post excerpt to accompany the headline by editing the feature-image custom field and setting the category to “Featured”.

We kept it pretty similar in color scheme to the last design, with the colors white, blue, and green. Also we have included the psd files for the logo, robo girl, and for the gadgets snapshots.

The theme is fully widgetized. A special feature of this theme as we use in many of our themes is the logo changer. You can use the default WordPress setting (“blog name”) or you can use your own logo. Upload your logo in the root folder of Gadgetizer theme and name it logo.png or you can use the logo.psd as a template. You will find the source in the root folder of the Tipz theme.

This theme also has a large footer bar that includes a links section, Flickr photostream, and latest comments section. Because some people might not like this option, we also included in the theme options the ability to have this section not show up.

The theme is using a few plugins, with some already integrated into functions.php, so there is no need to install them. The only plugin you need to install manually is FlickrRSS.  (FlickrRSS plugin is in the theme folder) (see the demo).

gadgetizer-2

Tagged as: No Comments
1612/092

AS3-StringParser 繁简体火星文转换

先来个Demo:

关于火星文,其实我有很多关于脑残的话要说,不过这里不谈火星文和脑残的关系,只谈前端开发的时候会碰到火星文的问题。
啥么?你说啥时候会碰到啊?
比如脏话过滤的时候,比如是否汉字判断的时候。
这个就要说到火星文的产生,以及编码段,大家自个儿去查wiki去。
别只顾着鄙视90后和火星文的存在,网站是需要兼容的,understand?

1512/092

Android-一些常用技巧

1.hideStatusbarAndTitlebar()隐藏statusbar和titlebar.

private void hideStatusbarAndTitlebar() {
	final Window win = getWindow();
	// No Statusbar
	win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
			WindowManager.LayoutParams.FLAG_FULLSCREEN);
	// No Titlebar
	requestWindowFeature(Window.FEATURE_NO_TITLE);
}

2.设置屏幕显示模式ScreenOrientation.

在activity里设置android:screenOrientation的值。
android:screenOrientation的属性有以下值:
unspecified(默认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
landscape,横屏
portrait,竖屏
user(用户当前设置的orientation值),The user's current preferred orientation.
behind(下一个要显示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
sensor(传感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
nosensor(不使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.

3.水平/垂直居中的方法.

设置parent的android:gravity为"center"。

4.获得当前屏幕宽高的方法.

Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();
Tagged as: 2 Comments
1412/090

APK-aPKMyFriends(名字大作战)

先来介绍下aPKMyFriends,aPKMyFriends到底是个什么东西呢?
先来看一个以前做的Flash game:NamePK
啊,不知道当时为什么做的是英文版的UI……这个游戏很简单,输入一个名字,再输入另一个,2个名字就开始PK,最后有一个会变扁趴下,举个例子,输入豆腐和豆奶,可能会得到这样的结果:
------------------------------------------------------------------------------------------------
比对敏捷值 豆奶 获得优先攻击权
豆奶 高唱我的菊花为谁开 伤害值为 117
但是 豆腐 闪开了
豆腐 搬起一块石头砸了过来 伤害值为 87
但是 豆奶 闪开了
豆奶 喝下一口酒精喷出一个大火球 伤害值为 109
但是 豆腐 闪开了
豆腐 使出了砖石星辰拳 伤害值为 96
豆奶 搬起一块石头砸了过来 伤害值为 126
但是 豆腐 闪开了
豆腐 搬起一块石头砸了过来 伤害值为 89
但是 豆奶 闪开了
豆奶 扔出了发着佛光的雅典娜 伤害值为 121
豆腐 喝下一口酒精喷出一个大火球 伤害值为 87
豆奶 喝下一口酒精喷出一个大火球 伤害值为 128
豆腐 喝下一口酒精喷出一个大火球 伤害值为 81
豆奶 扔出了发着佛光的雅典娜 伤害值为 121
豆腐 扔出了发着佛光的雅典娜 伤害值为 86
但是 豆奶 闪开了
豆奶 喝下一口酒精喷出一个大火球 伤害值为 136
豆腐 被扁趴下 豆奶 获得胜利
------------------------------------------------------------------------------------------------

1112/090

Android-各种Layout对象之FrameLayout,RelativeLayout

FrameLayout也是一个不常用到的布局容器:

FrameLayout is designed to block out an area on the screen to display a single item. You can add multiple children to a FrameLayout, but all children are pegged to the top left of the screen. Children are drawn in a stack, with the most recently added child on top. The size of the frame layout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits).

FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象 — 比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。FrameLayout的大小是最大的子元素的大小。
----------------------------------------------------------------------------------------------
RelativeLayout是用的比较多的一个Layout:

A Layout where the positions of the children can be described in relation to each other or to the parent. For the sake of efficiency, the relations between views are evaluated in one pass, so if view Y is dependent on the position of view X, make sure the view X comes first in the layout.

看描述是一个相对来说很自由的容器,比较麻烦的是每个需要被用来定位的容器都需要指定一个id。
下边直接来一个例子吧,比较好理解:

< ?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <textview android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hello man"/>
    <edittext android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/label"/>
    <button android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:text="OK"
        />
    <button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/ok"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="Cancel" />
</relativelayout>

效果:
RelativeLayout
RelativeLayout的参数相比其他Layout是非常多……而且在实际应用中应该是各种Layout相互嵌套……
唉,为何要有那么多的分辨率?为何?为虾米??!

1012/090

Android-各种Layout对象之TableLayout,AbsoluteLayout

TableLayout,顾名思义,就是一个表格布局的容器:

TableLayout positions its children into rows and columns. A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells cannot span columns, as they can in HTML.

TableLayout将子元素的位置分配到行或列中。一个TableLayout由许多的TableRow组成,每个TableRow都会定义一个row(事实上,你可以定义其它的子对象,这在下面会解释到)。TableLayout容器不会显示row、cloumns 或cell的边框线。每个row拥有0个或多个的cell;每个cell拥有一个View对象。表格由列和行组成许多的单元格。表格允许单元格为空。单元格不能跨列,这与HTML中的不一样。

Columns can be hidden, can be marked to stretch to fill available screen space, or can be marked as shrinkable to force the column to shrink until the table fits the screen. See the reference documentation for this class for more details.

列可以被隐藏,也可以被设置为伸展的从而填充可利用的屏幕空间,也可以被设置为强制列收缩直到表格匹配屏幕大小。对于更详细信息,可以查看 TableLayout类的参考文档。 (PS:如果发现该页被和谐,请蛋定,蛋定~)
--------------------------------------分割线----------------------------------------
下边是基本上不太用到的AbsoluteLayout,就是绝对定位,这个跟HTML里的差不多:

AbsoluteLayout enables children to specify exact x/y coordinates to display on the screen, where (0,0) is the upper left corner, and values increase as you move down or to the right. Margins are not supported, and overlapping elements are allowed (although not recommended). We generally recommend against using AbsoluteLayout unless you have good reasons to use it, because it is fairly rigid and does not work well with different device displays.

AbsoluteLayout可以让子元素指定准确的x/y坐标值,并显示在屏幕上。(0, 0)为左上角,当向下或向右移动时,坐标值将变大。AbsoluteLayout没有页边框,允许元素之间互相重叠(尽管不推荐)。我们通常不推荐使用 AbsoluteLayout,除非你有正当理由要使用它,因为它使界面代码太过刚性,以至于在不同的设备上可能不能很好地工作。
官方都不推荐用了,你觉得你在什么时候会用到?有时候的浮动广告?似乎是个不错的注意。

912/091

Android-各种Layout对象之LinearLayout

刚接触Android,相比iPhone App,上手很容易,但是由于Google的开放性,市面上目前有各种各样分辨率的屏幕!!于是,布局变的很重要,不然你的Apk可能在一些机器上的用户体验很不好,This's a question!
写完自己的HelloWorld之后就开始找关于分辨率的资料,接着就是针对分辨率的解决方案,然后就是面对各种Layout对象了。Android的Layout对象不多,不过可以互相组合,所以。。。很多时候还是靠经验来组合,或者学习别人的布局思想。
(PS:iPhone由于硬件的垄断性,加上Interface Builder,界面的布局非常的简单,非常的兼容,非常的和谐。)
下边开始进入正题:
先是最常见到的LinearLayout:

A LinearLayout aligns all children in a single direction — vertically or horizontally, depending on what property you set on the LinearLayout. All children are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). LinearLayout respects margins between children, and also gravity (right, center, or left alignment of a child).

LinearLayout以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子元素的高度加上边框高度)。LinearLayout保持子元素之间的间隔以及互相对齐(相对一个元素的右对齐、中间对齐或者左对齐)。

812/090

Android-l18n 工具Android Localizer

一个l18n(国际化/多语言化)工具,作者网站:http://www.artfulbits.com/Android/Localizer.aspx
Android Localizer是C#做的,所以需要安装.NET framework,软件是免费的,作者也开放了源代码。
功能也比较简单,就是自动帮忙生成对应的文件夹,然后给你个UI图形界面,不过提供了Google Translate,这到是个方便的功能。
来个图图瞧瞧:
Android Localizer

Tagged as: , No Comments
712/090

Android-模拟器皮肤HTC-HERO-HVGA-P

上星期挤了点时间做了个Android模拟器的皮肤,是针对SDK1.5的竖版HVGA屏Skin,图如下:
HTC-HERO-HVGA-P
说起来,其实做skin还是挺简单的,最麻烦的地方就是矫正坐标了,超累。
HTC-HERO-HVGA-P Skin下载地址:http://dl.dropbox.com/u/477487/Android/HTC-HERO-HVGA-P.rar.
恩,正好分享下Skin的做法。
打开默认的skin看看图片和background.png+layout文件,layout里的功能键基本就是英文名本身的意思,后边的坐标就是background.png对应的功能键位置了,看着办吧奥。

Tagged as: , , , No Comments
Page 1 of 212