Desktop softwares and information
Posts tagged tips
error RC1106: invalid option: -ologo
Aug 30th
After switch to vs2010, if you encounter the error:
Error 1 error RC1106: invalid option: -ologo
not only set the “Suppress Startup Banner” to “No” in Properties->Resources, but also need to set the “Enable Incremental Linking” to “No” in Properties->Linker.
给Android程序添加不同的广告平台
Jun 4th
本文假设已有一个广告,比如admob,然后添加另一广告,比如有米,用来在根据不同的语言自动调用不同的广告平台。
1. 在attrs.xml中追加一个declare-stylea,原有的属性不需要再定义。结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | < ?xml version="1.0" encoding="UTF-8"?> <resources> <declare -styleable name="com.admob.android.ads.AdView"> <attr name="testing" format="boolean" /> <attr name="backgroundColor" format="color" /> <attr name="textColor" format="color" /> <attr name="keywords" format="string" /> <attr name="refreshInterval" format="integer" /> <attr name="isGoneWithoutAd" format="boolean" /> </declare> <declare -styleable name="net.youmi.android.AdView"> <attr name="changeAdAnimation" format="boolean"/> <attr name="backgroundTransparent" format="integer"/> </declare> </resources> |
2. 为不同的区域创建不同的layout
首先在默认的layout目录中创建ads.xml文件,用于存放广告代码。在工程目录上右击,New->Android XML File,输入文件名ads.xml,结束。
然后为特定的语言创建ads.xml。在工程目录上右击,New->Android XML File,输入文件名ads.xml选择资源类型为Layout,添加Region为cn,添加Language为zh,结束。
3. 把针对于非中文的广告配置移动到layout/ads.xml文件中,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < ?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:admobsdk="http://schemas.android.com/apk/res/com.deskangel.dacalc" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com .admob.android.ads.AdView android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" admobsdk:backgroundColor="#000000" admobsdk:textColor="#FFFFFF" admobsdk:keywords="Android application" admobsdk:refreshInterval="60" admobsdk:testing="false" /> </merge> |
4. 把针对中文的广告配置移动到layout-zh-rCN/ads.xml文件中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < ?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:umadsdk="http://schemas.android.com/apk/res/com.deskangel.dacalc" android:layout_width="wrap_content" android:layout_height="wrap_content"> <net .youmi.android.AdView android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" umadsdk:refreshInterval="30" umadsdk:changeAdAnimation="false" umadsdk:backgroundTransparent="255" umadsdk:testing="false" umadsdk:isGoneWithoutAd="true" /> </merge> |
5. 在需要显示广告的地方添加:
1 2 3 4 5 | <include android:layout_height="wrap_content" layout="@layout/ads" android:id="@+id/incAds" android:layout_width="fill_parent" > </include> |
大功告成!非常简单的配置。
DaCalc Support normal mode
May 6th
Normal mode in DaCalc means DaCalc can work as a common calculator. User can input expression by the calculator panel instead of composing a formula at first, then load it. It saves much time in the scenario when users only want to do some simple calculations.
The another mode in DaCalc is Formula mode, which comes with the first release.
Normal mode is the default mode, but switching between them is easy. Click ‘Load’ in menu to load a formula will switch DaCalc to Formula mode. Click ‘Reset’ in menu will switch back to Normal mode again.
You will notice that the number panel is a litter different for Normal mode and Formula mode.
Try it yourself!
Android下的ListView一般应用指南
Apr 27th
一,显示:
ListView的Layout需要两个xml。第一个xml,在其中添加ListView本身,把ListView添加到需要显示的位置;第二个xml,则是定义ListView需要显示的内容的Layout。
定义ListView内容的Layout和一般的Layout一样,除了一些限制,比如不要在里面添加EditText之类带输入焦点的View。
info_list.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:layout_height="wrap_content"
android:id="@+id/txtName" android:layout_width="fill_parent" android:layout_weight="0.7" android:text="name" android:layout_marginRight="1px" android:background="#c0ffffb0" android:textColor="#000000"></TextView>
<TextView
android:layout_height="wrap_content"
android:id="@+id/txtExp"
android:layout_width="fill_parent" android:layout_weight="0.3" android:text="expression" android:background="#c0ffb600" android:textColor="#000000"></TextView>
</LinearLayout>
把ListView内容的Layout和ListView绑定在一起就可以显示了。一般的应用,使用SimpleAdapter就可以了:
SimpleAdapter listItemAdapter = new SimpleAdapter(this,
listItem,
R.layout.inf_list,
new String[] {"lstItmDate", "lstItmWeek"},
new int[] {R.id.txtvwWeek,R.id.txtvwWeekInfo});
SimpleAdapter的构造需要使用到一个List (listItem),使用如下的定义可以创建一个List:
ArrayList> listItem = new ArrayList>();
ArrayList需要使用到hashmap:
HashMap mapBase = new HashMap();
HashMap用来存储一对数值,比如:
mapBase.put("lstItmDate", "2010 04 26");
mapBase.put("lstItmWeek", "Monday");
可以很明显的看出来,HashMap中的”lstItmDate”和”lstItmWeek”与SimpleAdapter中的对应。
把HashMap添加到ArrayList中,显示部分就完成了:
listItem.add(mapBase);
所以,作为总结,一个ListView需要涉及如下几个部分:
- HashMap
- ArrayList
- SimpleAdapter
- ListView
滚动到TextView底部
Apr 22nd
在Android,一个单独的TextView是无法滚动的,需要放在一个ScrollView中。ScrollView提供了一系列的函数,其中fullScroll用来实现home和end键的功能,也就是滚动到顶部和底部。
但是,如果在TextView的append后面马上调用fullScroll,会发现无法滚动到真正的底部,这是因为Android下很多(如果不是全部的话)函数都是基于消息的,用消息队列来保证同步,所以函数调用多数是异步操作的。当TextView调用了append会,并不等text显示出来,而是把text的添加到消息队列之后立刻返回,fullScroll被调用的时候,text可能还没有显示,自然无法滚动到正确的位置。
解决的方法其实也很简单,使用post:
final ScrollView svResult = (ScrollView) findViewById(R.id.svResult);
svResult.post(new Runnable() {
public void run() {
svResult.fullScroll(ScrollView.FOCUS_DOWN);
}
});

Recent Comments