android中达到类似于windows桌面背景的平铺的效果,定义一个bitmap对象,在xml中和代码中均可,设置其tileMode为repeat。在drawable文件夹下建立如下文件tilebg.xml:
<?xml version ="1.0" encoding ="utf-8" ?>
<bitmap xmlns:android ="http://schemas.android.com/apk/res/android"
android:src ="@drawable/pattern"
android:tileMode ="repeat" />
其中pattern为需要平铺的图片,tileMode 属性定义平铺方向。在需要的地方设置background="@drawable/tilebg"
Java代码:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic);
//bitmap = Bitmap.createBitmap(100, 20, Config.ARGB_8888);
BitmapDrawable drawable = new BitmapDrawable(bitmap);
drawable.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );
drawable.setDither(true);
view.setBackgroundDrawable(drawable);
2)第二种我们使用xml来轻松实现
Java代码:
< bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="/blog_article/@drawable/img/index.html"
android:tileMode="repeat" />
3)第三种自己画出来
Java代码:
public static Bitmap createRepeater(int width, Bitmap src){
int count = (width + src.getWidth() - 1) / src.getWidth();
Bitmap bitmap = Bitmap.createBitmap(width, src.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
for(int idx = 0; idx < count; ++ idx){
canvas.drawBitmap(src, idx * src.getWidth(), 0, null);
}
return bitmap;
虽然xcode4.2已经带了自己的Master-Detail Application,但跟书上的都不一样
可书上还在用MainWindow.xib,这个已经不合适使用了。
新建一个空模板,然后新建UIViewController subclass,FirstLevelViewcontroller, 勾选 with xib
然后在代理类中,修改
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /* self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; */ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.rootViewController = [[[FirstLevelViewcontroller alloc] initWithNibName:@"FirstLevelViewcontroller" bundle:nil] autorelease]; self.window.rootViewController = self.rootViewController; [self.window makeKeyAndVisible]; return YES; }
在FirstLevelViewcontroller的Object上,拖入
drawSelectorOnTop:
When set to true, the selector will be drawn over the selected item. Otherwise the selector is drawn behind the selected item. The default value is false.
android:drawSelectorOnTop="true" 点击某一条记录,颜色会显示在最上面,记录上的文字被遮住,所以点击文字不放,文字就看不到
android:drawSelectorOnTop="false" 点击某条记录不放,颜色会在记录的后面,成为背景色,但是记录内容的文字是可见的