張慧的博客

          張慧的博客

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            45 Posts :: 0 Stories :: 24 Comments :: 0 Trackbacks

          2012年8月16日 #

          CSS(Cascading Style Sheet) 層疊樣式表,一種和Html聯系非常大的標記語言,主要用戶控制網頁的樣式,并能把樣式和網頁內容分離,因此能大大提高網頁開發的效率。

                 初識CSS,感覺這個名字有點難以理解,“樣式表”理解起來比較容易,就是定義網頁的樣式,也可以叫風格,那層疊怎么理解呢?

                 這要從CSS的繼承說起,學過面向對象的話,對繼承一定不陌生,CSS的繼承更簡單一些:

             

          在Html中各個標簽可以看作是一個個容器,例如:

          1. <span style="font-size:18px;"><p>詳解CSS的<em>名稱</em>含義</p></span>  

                 這一句話中,<p>標簽是一個大容器,里面有<em>標簽 ,我們把<p>標簽定義成父標簽,那么<em>標簽就成了子標簽。當我對<p>標簽(父標簽)用CSS樣式時,字標簽會完全繼承父標簽的風格,當然這種關系可能會有更多層(上面的例子為兩層):

          這張圖上,每個子標簽都會繼承父標簽的樣式,這種層層嵌套的關系,也就是CSS名稱的含義。

          posted @ 2012-08-16 22:29 張慧 閱讀(1664) | 評論 (0)編輯 收藏

          經常用到多個透明圖片層疊,但又需要獲取不同圖片的點擊事件,本文實現圖片透明區域穿透點擊事件。

          效果圖:

           歡迎轉載請說明轉自:http://blog.csdn.net/aminfo/article/details/7872748

          一、先上圖片,這2張圖片尺寸是一樣的,放到drawable目錄下:

          圖1:transparent.png

           

          圖2:transparent2.png

           

          二、上布局文件,test.xml

          <?xml version="1.0" encoding="utf-8"?>
          <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width
          ="fill_parent"
             android:layout_height
          ="fill_parent"
             android:orientation
          ="vertical"
             android:gravity
          ="center"
             android:id
          ="@+id/mainLayout">
             
              <ImageView android:id="@+id/ImageView01"
                  android:layout_width
          ="wrap_content"
                  android:layout_height
          ="wrap_content"
                  android:src
          ="@drawable/transparent"/>
              
              <ImageView android:id="@+id/ImageView02"
                  android:layout_width
          ="wrap_content"
                  android:layout_height
          ="wrap_content"
                  android:src
          ="@drawable/transparent2"/>    
                    
          </FrameLayout>

          package org.shuxiang.test;

          import android.app.Activity;
          import android.graphics.Bitmap;
          import android.graphics.drawable.BitmapDrawable;
          import android.os.Bundle;
          import android.util.Log;
          import android.view.MotionEvent;
          import android.view.View;
          import android.view.Window;
          import android.view.View.OnClickListener;
          import android.view.View.OnTouchListener;
          import android.widget.ImageView;

          public class MainActivity extends Activity
          {
              private ImageView iv1;
              private ImageView iv2;
              private Bitmap bitmap1, bitmap2;
              private boolean iv1Transparent = false;
              private boolean iv2Transparent = false;

              @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  requestWindowFeature(Window.FEATURE_NO_TITLE);
                  setContentView(R.layout.test);

                  iv1 = (ImageView) findViewById(R.id.ImageView01);
                  iv2 = (ImageView) findViewById(R.id.ImageView02);
                  bitmap1 = ((BitmapDrawable) (iv1.getDrawable())).getBitmap();
                  bitmap2 = ((BitmapDrawable) (iv2.getDrawable())).getBitmap();
                  
                  iv1.setOnClickListener(new OnClickListener(){
                      @Override
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
                          if(iv1Transparent)
                          {
                              Log.i("test", "圖1透明區域");
                          }
                          else
                          {
                              Log.i("test", "圖1點擊");                    
                          }
                      }
                      
                  });
                  
                  iv1.setOnTouchListener(new OnTouchListener()
                  {
                      @Override
                      public boolean onTouch(View arg0, MotionEvent arg1) 
                      {
                          // TODO Auto-generated method stub
                          if(bitmap1.getPixel((int)(arg1.getX()),((int)arg1.getY()))==0)
                          {
                              Log.i("test", "圖1透明區域");
                              iv1Transparent = true;    //透明區域設置true                    
                          }
                          else
                          {
                              Log.i("test", "圖1實體區域");
                              iv1Transparent = false;
                          }
                          return false;
                      }            
                  });
                  
                  iv2.setOnClickListener(new OnClickListener()
                  {
                      @Override
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
                          if(iv2Transparent)
                          {
                              Log.i("test", "圖2透明區域");
                          }
                          else
                          {
                              Log.i("test", "圖2點擊");                    
                          }
                      }
                      
                  });
                  
                  iv2.setOnTouchListener(new OnTouchListener()
                  {
                      @Override
                      public boolean onTouch(View v, MotionEvent event) {
                          // TODO Auto-generated method stub
                          if(bitmap2.getPixel((int)(event.getX()),((int)event.getY()))==0)
                          {
                              Log.i("test", "圖2透明區域");
                              iv2Transparent = true;    //透明區域設置true
                              iv1.dispatchTouchEvent(event);
                          }
                          else
                          {
                              Log.i("test", "圖2實體區域");
                              iv2Transparent = false;
                          }
                          return false;
                      }
                  });
              }
          }


          posted @ 2012-08-16 22:28 張慧 閱讀(3382) | 評論 (0)編輯 收藏


          需求大致分為三種:
          1.震動
          2.系統音效(無需提供音頻文件)
          3.自定義音效(需提供音頻文件)
          我的工具類的封裝:

          1. //  
          2. //  WQPlaySound.h  
          3. //  WQSound  
          4. //  
          5. //  Created by 念茜 on 12-7-20.  
          6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  
          7. //  
          8.   
          9. #import <UIKit/UIKit.h>  
          10. #import <AudioToolbox/AudioToolbox.h>  
          11.   
          12. @interface WQPlaySound : NSObject  
          13. {  
          14.     SystemSoundID soundID;  
          15. }  
          16.   
          17. /** 
          18.  *  @brief  為播放震動效果初始化 
          19.  * 
          20.  *  @return self 
          21.  */  
          22. -(id)initForPlayingVibrate;  
          23.   
          24. /** 
          25.  *  @brief  為播放系統音效初始化(無需提供音頻文件) 
          26.  * 
          27.  *  @param resourceName 系統音效名稱 
          28.  *  @param type 系統音效類型 
          29.  * 
          30.  *  @return self 
          31.  */  
          32. -(id)initForPlayingSystemSoundEffectWith:(NSString *)resourceName ofType:(NSString *)type;  
          33.   
          34. /** 
          35.  *  @brief  為播放特定的音頻文件初始化(需提供音頻文件) 
          36.  * 
          37.  *  @param filename 音頻文件名(加在工程中) 
          38.  * 
          39.  *  @return self 
          40.  */  
          41. -(id)initForPlayingSoundEffectWith:(NSString *)filename;  
          42.   
          43. /** 
          44.  *  @brief  播放音效 
          45.  */  
          46. -(void)play;  
          47.   
          48. @end  


          1. //  
          2. //  WQPlaySound.m  
          3. //  WQSound  
          4. //  
          5. //  Created by 念茜 on 12-7-20.  
          6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  
          7. //  
          8.   
          9. #import "WQPlaySound.h"  
          10.   
          11. @implementation WQPlaySound  
          12.   
          13. -(id)initForPlayingVibrate  
          14. {  
          15.     self = [super init];  
          16.     if (self) {  
          17.         soundID = kSystemSoundID_Vibrate;  
          18.     }  
          19.     return self;      
          20. }  
          21.   
          22. -(id)initForPlayingSystemSoundEffectWith:(NSString *)resourceName ofType:(NSString *)type  
          23. {  
          24.     self = [super init];  
          25.     if (self) {  
          26.         NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:resourceName ofType:type];  
          27.         if (path) {  
          28.             SystemSoundID theSoundID;  
          29.             OSStatus error =  AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &theSoundID);  
          30.             if (error == kAudioServicesNoError) {  
          31.                 soundID = theSoundID;  
          32.             }else {  
          33.                 NSLog(@"Failed to create sound ");  
          34.             }  
          35.         }  
          36.           
          37.     }  
          38.     return self;  
          39. }  
          40.   
          41. -(id)initForPlayingSoundEffectWith:(NSString *)filename  
          42. {  
          43.     self = [super init];  
          44.     if (self) {  
          45.         NSURL *fileURL = [[NSBundle mainBundle] URLForResource:filename withExtension:nil];  
          46.         if (fileURL != nil)  
          47.         {  
          48.             SystemSoundID theSoundID;  
          49.             OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileURL, &theSoundID);  
          50.             if (error == kAudioServicesNoError){  
          51.                 soundID = theSoundID;  
          52.             }else {  
          53.                 NSLog(@"Failed to create sound ");  
          54.             }  
          55.         }  
          56.     }  
          57.     return self;  
          58. }  
          59.   
          60. -(void)play  
          61. {  
          62.     AudioServicesPlaySystemSound(soundID);  
          63. }  
          64.   
          65. -(void)dealloc  
          66. {   
          67.     AudioServicesDisposeSystemSoundID(soundID);  
          68. }  
          69. @end  


          調用方法步驟:
          1.加入AudioToolbox.framework到工程中
          2.調用WQPlaySound工具類

          2.1震動

          1. WQPlaySound *sound = [[WQPlaySound alloc]initForPlayingVibrate];  
          2. [sound play];  

          2.2系統音效,以Tock為例

          1. WQPlaySound *sound = [[WQPlaySound alloc]initForPlayingSystemSoundEffectWith:@"Tock" ofType:@"aiff"];  
          2. [sound play];  

          2.3自定義音效,將tap.aif音頻文件加入到工程

          1. WQPlaySound *sound = [[WQPlaySound alloc]initForPlayingSoundEffectWith:@"tap.aif"];  
          2. [sound play];  

          tap.aif音頻文件樣例下載點擊

          posted @ 2012-08-16 22:26 張慧 閱讀(7774) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 宝清县| 会同县| 余庆县| 文昌市| 乌什县| 贡嘎县| 宁波市| 赣州市| 腾冲县| 翁牛特旗| 重庆市| 西安市| 阿合奇县| 巴彦县| 贵溪市| 普陀区| 大化| 陆良县| 尉氏县| 高淳县| 海淀区| 特克斯县| 鹤庆县| 百色市| 绥宁县| 宁国市| 阿鲁科尔沁旗| 永济市| 巴青县| 双鸭山市| 垫江县| 和平区| 济宁市| 南木林县| 泰兴市| 三江| 南投县| 东乡| 达日县| 顺平县| 崇礼县|