当前位置: 编程技术>移动开发
本页文章导读:
▪银屏的适配 屏幕的适配其实无论是国际化也好,还是屏幕的适配也好。对于Android来说,其实都是操作文件夹就行了
在进行屏幕的适配的时候,要遵循的命名规则如下:
例子: layout-320x240
解释:
1)大的数.........
▪ java调用百度mapAPI反解析经纬码返回地址信息 java调用百度地图API反解析经纬码返回地址信息import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.io.BufferedReader;
imp.........
▪ 浅析objc的讯息机制 浅析objc的消息机制 学习ios的同学都知道ojbc一种runtime的语言,runtime表明函数的真正执行的时候来确定函数执行的。这样的好处就是我们能很灵活的设计我们的代码,也能在看似合法的情况.........
[1]银屏的适配
来源: 互联网 发布时间: 2014-02-18
屏幕的适配
其实无论是国际化也好,还是屏幕的适配也好。对于Android来说,其实都是操作文件夹就行了
在进行屏幕的适配的时候,要遵循的命名规则如下:
例子: layout-320x240
解释:
1)大的数要放在前面
2)所需要的布局文件可以从其他文件夹里面拷(因为如果新建一个的话,它会提示你该文件已经存在。其实也是可以的)
演示的例子的截图:
480x320:
320x240
[2] java调用百度mapAPI反解析经纬码返回地址信息
来源: 互联网 发布时间: 2014-02-18
java调用百度地图API反解析经纬码返回地址信息
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.apache.commons.lang.StringUtils;
public class BaiduAPI {
private static String ak = "5ef2641d89438a6e708db122820cf1d2";
public static Map<String, String> testPost(String x, String y) throws IOException {
URL url = new URL("http://api.map.baidu.com/geocoder?" + ak + "=您的密钥" +
"&callback=renderReverse&location=" + x
+ "," + y + "&output=json");
URLConnection connection = url.openConnection();
/**
* 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。
* 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做:
*/
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection
.getOutputStream(), "utf-8");
// remember to clean up
out.flush();
out.close();
// 一旦发送成功,用以下方法就可以得到服务器的回应:
String res;
InputStream l_urlStream;
l_urlStream = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(
l_urlStream,"UTF-8"));
StringBuilder sb = new StringBuilder("");
while ((res = in.readLine()) != null) {
sb.append(res.trim());
}
String str = sb.toString();
System.out.println(str);
Map<String,String> map = null;
if(StringUtils.isNotEmpty(str)) {
int addStart = str.indexOf("formatted_address\":");
int addEnd = str.indexOf("\",\"business");
if(addStart > 0 && addEnd > 0) {
String address = str.substring(addStart+20, addEnd);
map = new HashMap<String,String>();
map.put("address", address);
return map;
}
}
return null;
}
public static void main(String[] args) throws IOException {
Map<String, String> json = BaiduAPI.testPost("29.542938", "114.064022");
System.out.println("address :" + json.get("address"));
}
}
[3] 浅析objc的讯息机制
来源: 互联网 发布时间: 2014-02-18
浅析objc的消息机制
现在明了了,super_class是其父类的指针,name是类名,version,info,instance_size是表明这个类的信息, ivars是这个类的变量列表,methodLists是函数列表,cache,是一个方法的list的cache,protocols当然是一个protocol的list。
学习ios的同学都知道ojbc一种runtime的语言,runtime表明函数的真正执行的时候来确定函数执行的。这样的好处就是我们能很灵活的设计我们的代码,也能在看似合法的情况下做一些非常有意思的事情,要了解ios的runtime,我们需要了解ios的类结构,ios所有的类的基类都是NSObject这个类,从这个类来分析ios的runtime机制。
下面我们在xcode 中打开 NSObject 的声明,为了简单明了,我省略了很多,类型和宏的声明。
NS_ROOT_CLASS
@interface NSObject <NSObject> {
Class isa;
}
+ (void)load;
+ (void)initialize;
- (id)init;
+ (id)new;
+ (id)allocWithZone:(NSZone *)zone;
+ (id)alloc;
- (void)dealloc;
- (void)finalize;
- (id)copy;
- (id)mutableCopy;
+ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
+ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
+ (Class)superclass;
+ (Class)class;
+ (BOOL)instancesRespondToSelector:(SEL)aSelector;
+ (BOOL)conformsToProtocol:(Protocol *)protocol;
- (IMP)methodForSelector:(SEL)aSelector;
+ (IMP)instanceMethodForSelector:(SEL)aSelector;
- (void)doesNotRecognizeSelector:(SEL)aSelector;
- (id)forwardingTargetForSelector:(SEL)aSelector NS_AVAILABLE(10_5, 2_0);
- (void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
+ (NSMethodSignature *)instanceMethodSignatureForSelector:(SEL)aSelector;
- (BOOL)allowsWeakReference NS_UNAVAILABLE;
- (BOOL)retainWeakReference NS_UNAVAILABLE;
+ (NSString *)description;
+ (BOOL)isSubclassOfClass:(Class)aClass;
+ (BOOL)resolveClassMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0);
+ (BOOL)resolveInstanceMethod:(SEL)sel NS_AVAILABLE(10_5, 2_0);
@end
如您所见,NSObject的对象非常之简单,Class 类型的,我们再看Class 是什么:
#include <sys/types.h> // for __DARWIN_NULL
#include <Availability.h>
#include <objc/objc-api.h>
typedef struct objc_class *Class;
typedef struct objc_object {
Class isa;
} *id;
ok,Class是一个 objc_class 的结构体的指针,现在我们只要了解objc_class的结构就好了。
typedef struct objc_method *Method;
typedef struct objc_ivar *Ivar;
typedef struct objc_category *Category;
typedef struct objc_property *objc_property_t;
struct objc_class {
Class isa;
#if !__OBJC2__
Class super_class OBJC2_UNAVAILABLE;
const char *name OBJC2_UNAVAILABLE;
long version OBJC2_UNAVAILABLE;
long info OBJC2_UNAVAILABLE;
long instance_size OBJC2_UNAVAILABLE;
struct objc_ivar_list *ivars OBJC2_UNAVAILABLE;
struct objc_method_list **methodLists OBJC2_UNAVAILABLE;
struct objc_cache *cache OBJC2_UNAVAILABLE;
struct objc_protocol_list *protocols OBJC2_UNAVAILABLE;
#endif
} OBJC2_UNAVAILABLE;
现在明了了,super_class是其父类的指针,name是类名,version,info,instance_size是表明这个类的信息, ivars是这个类的变量列表,methodLists是函数列表,cache,是一个方法的list的cache,protocols当然是一个protocol的list。
好了,我们对NSobject 类有了基本的了解了,
[aObjec performSelector:aSEL]; 当这行代码执行的时候,aObject 首先会去找cache,里头有没有对应函数,如果找不到,会去找methodLists 列表中是否含有对应的函数,如果再没有就会去找 super_class 中的cache,然后..... 继续这样的步骤.......
所以我们现在了解了NSObject 对于消息的发送的基本的机制流程,后续我会介绍NSOject 我们在这个机制上能做的一些事情。
最新技术文章: