<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    咖啡伴侶

    呆在上海
    posts - 163, comments - 156, trackbacks - 0, articles - 2

    屏幕大小
    1、不同的layout

          Android手機(jī)屏幕大小不一,有480x320,640x360,800x480.怎樣才能讓App自動(dòng)適應(yīng)不同的屏幕呢? 其實(shí)很簡(jiǎn)單,只需要在res目錄下創(chuàng)建不同的layout文件夾,比如:layout-640x360,layout-800x480,所有的 layout文件在編譯之后都會(huì)寫(xiě)入R.java里,而系統(tǒng)會(huì)根據(jù)屏幕的大小自己選擇合適的layout進(jìn)行使用。

    2、hdpi、mdpi、ldpi

          前的版本中,只有一個(gè)drawable,而2.1版本中有drawable-mdpi、drawable-ldpi、drawable-hdpi三個(gè),這三個(gè)主要是為了支持多分辨率。

    drawable- hdpi、drawable- mdpi、drawable-ldpi的區(qū)別:

    1.drawable-hdpi里面存放高分辨率的圖片,如WVGA (480x800),FWVGA (480x854)
    2.drawable-mdpi里面存放中等分辨率的圖片,如HVGA (320x480)
    3.drawable-ldpi里面存放低分辨率的圖片,如QVGA (240x320)
    系統(tǒng)會(huì)根據(jù)機(jī)器的分辨率來(lái)分別到這幾個(gè)文件夾里面去找對(duì)應(yīng)的圖片。在開(kāi)發(fā)程序時(shí)為了兼容不同平臺(tái)不同屏幕,建議各自文件夾根據(jù)需求均存放不同版本圖片。

    屏幕方向
    1、橫屏豎屏自動(dòng)切換

          可以在res目錄下建立layout-port和layout-land兩個(gè)目錄,里面分別放置豎屏和橫屏兩種布局文件,這樣在手機(jī)屏幕方向變化的時(shí)候系統(tǒng)會(huì)自動(dòng)調(diào)用相應(yīng)的布局文件,避免一種布局文件無(wú)法滿(mǎn)足兩種屏幕顯示的問(wèn)題。

    2、禁用自動(dòng)切換

    只需要在AndroidManifest.xml文件中加入android:screenOrientation屬性限制。

    •Android:screenOrientation="landscape"  //是限制此頁(yè)面橫屏顯示
    •Android:screenOrientation="portrait"      //是限制此頁(yè)面數(shù)豎屏顯示
    字體自適應(yīng)大小
    方法1:

    首先根據(jù)不同分辨率獲取不同字體大小。
    在RES里創(chuàng)建
    values-480x320/strings.xml 里面設(shè)置<dimen name="Text_size">30px</dimen>

    values-800x400/strings.xml 里面設(shè)置<dimen name="Text_size">30px</dimen>

    分別代表480X320 和 800X400分辨率情況下 字號(hào)為30px和40px;

    在java文件中這樣調(diào)用

    int sizeOfText = (int) this.getResources().getDimension(R.dimen.Text_size);

    方法2:

    在視圖的 onsizechanged里獲取視圖寬度,一般情況下默認(rèn)寬度是320,所以計(jì)算一個(gè)縮放比率rate = (float) w/320   w是實(shí)際寬度
    然后在設(shè)置字體尺寸時(shí) paint.setTextSize((int)(8*rate));   8是在分辨率寬為320 下需要設(shè)置的字體大小實(shí)際字體大小 = 默認(rèn)字體大小 x  rate

    posted @ 2011-09-02 09:28 oathleo 閱讀(1258) | 評(píng)論 (0)編輯 收藏

    首先內(nèi)部存儲(chǔ)路徑為/data/data/youPackageName/,下面講解的各路徑都是基于你自己的應(yīng)用的內(nèi)部存儲(chǔ)路徑下。所有內(nèi)部存儲(chǔ)中保存的文件在用戶(hù)卸載應(yīng)用的時(shí)候會(huì)被刪除。

    一、 files
    1. Context.getFilesDir(),該方法返回/data/data/youPackageName/files的File對(duì)象。
    2. Context.openFileInput()與Context.openFileOutput(),只能讀取和寫(xiě)入files下的文件,返回的是FileInputStream和FileOutputStream對(duì)象。
    3. Context.fileList(),返回files下所有的文件名,返回的是String[]對(duì)象。
    4. Context.deleteFile(String),刪除files下指定名稱(chēng)的文件。

    二、cache
    1. Context.getCacheDir(),該方法返回/data/data/youPackageName/cache的File對(duì)象。

    三、custom dir

    getDir(String name, int mode),返回/data/data/youPackageName/下的指定名稱(chēng)的文件夾File對(duì)象,如果該文件夾不存在則用指定名稱(chēng)創(chuàng)建一個(gè)新的文件夾。



    有了數(shù)據(jù)存儲(chǔ) API,您可以使用內(nèi)部存儲(chǔ)器存儲(chǔ)數(shù)據(jù)。信息可以是私有的,您可以有選擇地讓其他應(yīng)用程序?qū)χ哂凶x或?qū)懙脑L問(wèn)權(quán)限。本節(jié)介紹這個(gè)存儲(chǔ)私有數(shù)據(jù)的 API,它使用 android.content.Context.openFileInput、openFileOutput 和 getCacheDir() 來(lái)高速緩存數(shù)據(jù),而不是永久地存儲(chǔ)。

    清單 20 中的代碼片段展示了如何從內(nèi)部私有存儲(chǔ)器讀取數(shù)據(jù)。使得存儲(chǔ)器為私有的方法是對(duì) openFileOutput() 使用MODE_PRIVATE。


    清單 20. 從本地私有存儲(chǔ)器讀取數(shù)據(jù)

    /**
     * Writes content to internal storage making the content private to 
     * the application. The method can be easily changed to take the MODE 
     * as argument and let the caller dictate the visibility: 
     * MODE_PRIVATE, MODE_WORLD_WRITEABLE, MODE_WORLD_READABLE, etc.
     * 
     * 
    @param filename - the name of the file to create
     * 
    @param content - the content to write
     
    */
    public void writeInternalStoragePrivate(
            String filename, 
    byte[] content) {
        
    try {
            
    //MODE_PRIVATE creates/replaces a file and makes 
            
    //  it private to your application. Other modes:
            
    //    MODE_WORLD_WRITEABLE
            
    //    MODE_WORLD_READABLE
            
    //    MODE_APPEND
            FileOutputStream fos = 
               openFileOutput(filename, Context.MODE_PRIVATE);
            fos.write(content);
            fos.close();
        } 
    catch (FileNotFoundException e) {
            e.printStackTrace();
        } 
    catch (IOException e) {
            e.printStackTrace();
        }
    }


    清單 21 中的代碼片段展示了如何從內(nèi)部私有存儲(chǔ)器讀取數(shù)據(jù);注意 openFileInput() 的使用。


    清單 21. 從內(nèi)部私有存儲(chǔ)器讀取數(shù)據(jù)

    /**
     * Reads a file from internal storage
     * 
    @param filename the file to read from
     * 
    @return the file content
     
    */
    public byte[] readInternalStoragePrivate(String filename) {
        
    int len = 1024;
        
    byte[] buffer = new byte[len];
        
    try {
            FileInputStream fis 
    = openFileInput(filename);
            ByteArrayOutputStream baos 
    = new ByteArrayOutputStream();
            
    int nrb = fis.read(buffer, 0, len); // read up to len bytes
            while (nrb != -1) {
                baos.write(buffer, 
    0, nrb);
                nrb 
    = fis.read(buffer, 0, len);
            }
            buffer 
    = baos.toByteArray();
            fis.close();
        } 
    catch (FileNotFoundException e) {
            e.printStackTrace();
        } 
    catch (IOException e) {
            e.printStackTrace();
        }
        
    return buffer;
    }


    清單 22 展示了如何從內(nèi)部私有存儲(chǔ)器刪除數(shù)據(jù)。


    清單 22. 從本地私有存儲(chǔ)器刪除數(shù)據(jù)

        
    /**
     * Delete internal private file
     * @param filename - the filename to delete
     */
    public void deleteInternalStoragePrivate(String filename) {
        File file = getFileStreamPath(filename);
        if (file != null) {
            file.delete();
        }
    }


    現(xiàn)在可以來(lái)看為公共數(shù)據(jù)使用外部存儲(chǔ)器了。

    回頁(yè)首

    為公共數(shù)據(jù)使用設(shè)備的外部存儲(chǔ)器

    有了數(shù)據(jù)存儲(chǔ) API,您可以使用外部存儲(chǔ)器存儲(chǔ)數(shù)據(jù)。信息可以是私有的,您可以有選擇地讓其他應(yīng)用程序?qū)χ哂凶x或?qū)懙脑L問(wèn)權(quán)限。本節(jié)您將對(duì)此 API 進(jìn)行編程,以便使用包括getExternalStorageState()、getExternalFilesDir()、getExternalStorageDirectory() 和getExternalStoragePublicDirectory() 在內(nèi)的很多 API 來(lái)存儲(chǔ)公共數(shù)據(jù)。您為公共數(shù)據(jù)使用下面的路徑:/Android/data/<package_name>/files/。

    在使用外部存儲(chǔ)器之前,必須看看它是否可用,是否可寫(xiě)。下面兩個(gè)代碼片段展示了測(cè)試這些條件的幫助器方法。清單 23 測(cè)試外部存儲(chǔ)器是否可用。


    清單 23. 測(cè)試外部存儲(chǔ)器是否可用

        
    /**
     * Helper Method to Test if external Storage is Available
     */
    public boolean isExternalStorageAvailable() {
        boolean state = false;
        String extStorageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
            state = true;
        }
        return state;
    }


    清單 24 測(cè)試外部存儲(chǔ)器是否只可讀。


    清單 24. 測(cè)試外部存儲(chǔ)器是否只可讀

        
    /**
     * Helper Method to Test if external Storage is read only
     */
    public boolean isExternalStorageReadOnly() {
        boolean state = false;
        String extStorageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
            state = true;
        }
        return state;
    }


    清單 25 展示了如何寫(xiě)到外部存儲(chǔ)器,以存儲(chǔ)公共數(shù)據(jù)。


    清單 25. 寫(xiě)到外部?jī)?nèi)存

        
    /**
     * Write to external public directory
     * @param filename - the filename to write to
     * @param content - the content to write
     */
    public void writeToExternalStoragePublic(String filename, byte[] content) {

        // API Level 7 or lower, use getExternalStorageDirectory()
        //  to open a File that represents the root of the external
        // storage, but writing to root is not recommended, and instead
        // application should write to application-specific directory, as shown below.

        String packageName = this.getPackageName();
        String path = "/Android/data/" + packageName + "/files/";

        if (isExternalStorageAvailable() &&
           !isExternalStorageReadOnly()) {
            try {
                File file = new File(path, filename);
                file.mkdirs();
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(content);
                fos.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    清單 26 展示了如何從外部存儲(chǔ)器讀取數(shù)據(jù)。


    清單 26. 從外部?jī)?nèi)存讀取數(shù)據(jù)

        
    /**
     * Reads a file from internal storage
     * @param filename - the filename to read from
     * @return the file contents
     */
    public byte[] readExternallStoragePublic(String filename) {
        int len = 1024;
        byte[] buffer = new byte[len];
        String packageName = this.getPackageName();
        String path = "/Android/data/" + packageName + "/files/";

        if (!isExternalStorageReadOnly()) {     
            try {
                File file = new File(path, filename);            
                FileInputStream fis = new FileInputStream(file);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int nrb = fis.read(buffer, 0, len); //read up to len bytes
                while (nrb != -1) {
                    baos.write(buffer, 0, nrb);
                    nrb = fis.read(buffer, 0, len);
                }
                buffer = baos.toByteArray();
                fis.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return buffer;
    }


    清單 27 中的代碼片段展示了如何從外部?jī)?nèi)存刪除文件。


    清單 27. 從外部?jī)?nèi)存刪除文件

        
    /**
     * Delete external public file
     * @param filename - the filename to write to
     */
    void deleteExternalStoragePublicFile(String filename) {
        String packageName = this.getPackageName();
        String path = "/Android/data/" + packageName + "/files/"+filename;
        File file = new File(path, filename);
        if (file != null) {
            file.delete();
        }
    }


    處理外部存儲(chǔ)器需要特殊的權(quán)限 WRITE_EXTERNAL_STORAGE,它通過(guò) AndroidManifest.xml 請(qǐng)求得到(參見(jiàn) 清單 28)。


    清單 28. WRITE_EXTERNAL_STORAGE

        
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


    外部存儲(chǔ) API 通過(guò)根據(jù)文件類(lèi)型(比如 Pictures、Ringtones)將文件存儲(chǔ)在預(yù)先確定的目錄中,允許您公共地存儲(chǔ)文件。本文沒(méi)有介紹這種方法,但是您應(yīng)該熟悉它。此外,記住外部存儲(chǔ)器中的文件任何時(shí)候都可能消失。

    回頁(yè)首

    相關(guān)的方法

    如果您具有不需要長(zhǎng)期永久保存的臨時(shí)文件,那么可以將這些文件存儲(chǔ)在高速緩存中。高速緩存是一種特殊的內(nèi)存,可以用于存儲(chǔ)中小型數(shù)據(jù)(少于兆字節(jié)),但是您一定要知道,取決于有多少內(nèi)存可用,高速緩存的內(nèi)容任何時(shí)候都可能被清除。

    清單 29 展示了一個(gè)幫助器方法,它返回到內(nèi)部?jī)?nèi)存中高速緩存的路徑。


    清單 29. 檢索到內(nèi)部?jī)?nèi)存高速緩存的路徑

        
    /**
     * Helper method to retrieve the absolute path to the application
     * specific internal cache directory on the file system. These files
     * will be ones that get deleted when the application is uninstalled or when
     * the device runs low on storage. There is no guarantee when these
     * files will be deleted.
     *
     * Note: This uses a Level 8+ API.
     *
     * @return the absolute path to the application specific cache
     * directory
     */
    public String getInternalCacheDirectory() {
        String cacheDirPath = null;
        File cacheDir = getCacheDir();
        if (cacheDir != null) {
            cacheDirPath = cacheDir.getPath();
        }
        return cacheDirPath;        
    }


    清單 30 展示了一個(gè)幫助器方法,它返回到外部?jī)?nèi)存中高速緩存的路徑。


    清單 30. 檢索到外部?jī)?nèi)存高速緩存的路徑

        
    /**
     * Helper method to retrieve the absolute path to the application
     * specific external cache directory on the file system. These files
     * will be ones that get deleted when the application is uninstalled or when
     * the device runs low on storage. There is no guarantee when these
     * files will be deleted.
     *
     * Note: This uses a Level 8+ API.
     *
     * @return the absolute path to the application specific cache
     * directory
     */
    public String getExternalCacheDirectory() {
        String extCacheDirPath = null;
        File cacheDir = getExternalCacheDir();
        if (cacheDir != null) {
            extCacheDirPath = cacheDir.getPath();
        }
        return extCacheDirPath;     
    }

     


    通過(guò)使用示例應(yīng)用程序,您現(xiàn)在應(yīng)該很好地理解了如何為公共數(shù)據(jù)使用設(shè)備的外部存儲(chǔ)器。

    posted @ 2011-08-31 13:17 oathleo 閱讀(2926) | 評(píng)論 (0)編輯 收藏

    WebView對(duì)Javascript的支持也很強(qiáng),google一個(gè)Java和Javascript互調(diào)的例子  
    整個(gè)Eclipse ADT工程例子中都有,這里重點(diǎn)分析一下代碼:
    Java代碼  收藏代碼
    1. public class WebViewDemo extends Activity {  
    2.     private WebView mWebView;  
    3.     private Handler mHandler = new Handler();  
    4.   
    5.     public void onCreate(Bundle icicle) {  
    6.         super.onCreate(icicle);  
    7.         setContentView(R.layout.webviewdemo);  
    8.         mWebView = (WebView) findViewById(R.id.webview);  
    9.         WebSettings webSettings = mWebView.getSettings();  
    10.         webSettings.setJavaScriptEnabled(true);  
    11.         mWebView.addJavascriptInterface(new Object() {  
    12.             public void clickOnAndroid() {  
    13.                 mHandler.post(new Runnable() {  
    14.                     public void run() {  
    15.                         mWebView.loadUrl("javascript:wave()");  
    16.                     }  
    17.                 });  
    18.             }  
    19.         }, "demo");  
    20.         mWebView.loadUrl("file:///android_asset/demo.html");  
    21.     }  
    22. }  

    這 里的重點(diǎn)是addJavascriptInterface(Object obj,String interfaceName)方法,該方法將一個(gè)java對(duì)象綁定到一個(gè)javascript對(duì)象中,javascript對(duì)象名就是 interfaceName,作用域是Global。這樣初始化webview后,在webview加載的頁(yè)面中就可以直接通過(guò) javascript:window.demo訪問(wèn)到綁定的java對(duì)象了。來(lái)看看在html中是怎樣調(diào)用的:

    Html代碼  收藏代碼
    1. <html>  
    2.         <script language="javascript">  
    3.                 function wave() {  
    4.                     document.getElementById("droid").src="android_waving.png";  
    5.                 }  
    6.         </script>  
    7.         <body>  
    8.             <a onClick="window.demo.clickOnAndroid()">  
    9.                                 <img id="droid" src="android_normal.png"/><br>  
    10.                                 Click me!  
    11.             </a>  
    12.         </body>  
    13. </html>  

     這樣在javascript中就可以調(diào)用java對(duì)象的clickOnAndroid()方法了,wave()方法是java中調(diào)用javascript的例子。

    這里還有幾個(gè)知識(shí)點(diǎn):

    1) 為了讓W(xué)ebView從apk文件中加載assets,Android SDK提供了一個(gè)schema,前綴為"file:///android_asset/"。WebView遇到這樣的schema,就去當(dāng)前包中的 assets目錄中找內(nèi)容。如上面的"file:///android_asset/demo.html"

    2)addJavascriptInterface方法中要綁定的Java對(duì)象及方法要運(yùn)行另外的線程中,不能運(yùn)行在構(gòu)造他的線程中,這也是使用Handler的目的。

    posted @ 2011-08-25 15:36 oathleo 閱讀(1006) | 評(píng)論 (0)編輯 收藏

        <property name="proguard-home" value="D:/proguard4.4/lib"/>
        
    <property name="android-jar" value="D:\android3.0\android-sdk_r12-windows\android-sdk-windows\platforms\android-8\android.jar"/>
    //指定 proguard 地址和 android地址


    <java jar="${proguard-home}/proguard.jar" fork="true" failonerror="true">
                
    <jvmarg value="-Dmaximum.inlined.code.length=32" />
                
    <arg value="-injars ${target_temp_jar}" />
                
    <arg value="-outjars ${target_jar}" />
                
    //第三方包
                <arg value="-libraryjars ${android-jar}" />
                
    <arg value="-libraryjars lib/android_script.jar" />

                
    <!--  <arg value="-libraryjars ${external-libs}/*.jar"/>-->
                
    <arg value="-dontpreverify" />
                
    <arg value="-dontoptimize" />
                
    <arg value="-dontusemixedcaseclassnames" />
                
    <arg value="-repackageclasses ''" />
                
    <arg value="-allowaccessmodification" />
                
                
    <!--保護(hù)public字段-->
                
    <arg value="-keepclassmembers public class * { public protected *; }" />
                
    <!--保護(hù)泛型-->
                
    <arg value="-keepattributes Signature" />

                
    <arg value="-keep public class com.xxxcore.*" />
                
    <arg value="-keep public class com.xxxviewer.**" />
     
                
    <arg value="-optimizationpasses 7" />
                
    <arg value="-verbose" />
                
    <arg value="-dontskipnonpubliclibraryclasses" />
                
    <arg value="-dontskipnonpubliclibraryclassmembers" />
            
    </java>

            
    <signjar jar="${target_jar}" keystore="${sign.keystore}" alias="${sign.alias}" keypass="${sign.keypass}" storepass="${sign.storepass}"/>
            
    <delete file="${target_temp_jar}" />
        
    </target>




    參數(shù):

    -include {filename}    從給定的文件中讀取配置參數(shù)

    -basedirectory {directoryname}    指定基礎(chǔ)目錄為以后相對(duì)的檔案名稱(chēng)

    -injars {class_path}    指定要處理的應(yīng)用程序jar,war,ear和目錄

    -outjars {class_path}    指定處理完后要輸出的jar,war,ear和目錄的名稱(chēng)

    -libraryjars {classpath}    指定要處理的應(yīng)用程序jar,war,ear和目錄所需要的程序庫(kù)文件

    -dontskipnonpubliclibraryclasses    指定不去忽略非公共的庫(kù)類(lèi)。

    -dontskipnonpubliclibraryclassmembers    指定不去忽略包可見(jiàn)的庫(kù)類(lèi)的成員。


    保留選項(xiàng)
    -keep {Modifier} {class_specification}    保護(hù)指定的類(lèi)文件和類(lèi)的成員

    -keepclassmembers {modifier} {class_specification}    保護(hù)指定類(lèi)的成員,如果此類(lèi)受到保護(hù)他們會(huì)保護(hù)的更好

    -keepclasseswithmembers {class_specification}    保護(hù)指定的類(lèi)和類(lèi)的成員,但條件是所有指定的類(lèi)和類(lèi)成員是要存在。

    -keepnames {class_specification}    保護(hù)指定的類(lèi)和類(lèi)的成員的名稱(chēng)(如果他們不會(huì)壓縮步驟中刪除)

    -keepclassmembernames {class_specification}    保護(hù)指定的類(lèi)的成員的名稱(chēng)(如果他們不會(huì)壓縮步驟中刪除)

    -keepclasseswithmembernames {class_specification}    保護(hù)指定的類(lèi)和類(lèi)的成員的名稱(chēng),如果所有指定的類(lèi)成員出席(在壓縮步驟之后)

    -printseeds {filename}    列出類(lèi)和類(lèi)的成員-keep選項(xiàng)的清單,標(biāo)準(zhǔn)輸出到給定的文件

    壓縮
    -dontshrink    不壓縮輸入的類(lèi)文件

    -printusage {filename}

    -whyareyoukeeping {class_specification}    

    優(yōu)化
    -dontoptimize    不優(yōu)化輸入的類(lèi)文件

    -assumenosideeffects {class_specification}    優(yōu)化時(shí)假設(shè)指定的方法,沒(méi)有任何副作用

    -allowaccessmodification    優(yōu)化時(shí)允許訪問(wèn)并修改有修飾符的類(lèi)和類(lèi)的成員

    混淆
    -dontobfuscate    不混淆輸入的類(lèi)文件

    -printmapping {filename}

    -applymapping {filename}    重用映射增加混淆

    -obfuscationdictionary {filename}    使用給定文件中的關(guān)鍵字作為要混淆方法的名稱(chēng)

    -overloadaggressively    混淆時(shí)應(yīng)用侵入式重載

    -useuniqueclassmembernames    確定統(tǒng)一的混淆類(lèi)的成員名稱(chēng)來(lái)增加混淆

    -flattenpackagehierarchy {package_name}    重新包裝所有重命名的包并放在給定的單一包中

    -repackageclass {package_name}    重新包裝所有重命名的類(lèi)文件中放在給定的單一包中

    -dontusemixedcaseclassnames    混淆時(shí)不會(huì)產(chǎn)生形形色色的類(lèi)名

    -keepattributes {attribute_name,}    保護(hù)給定的可選屬性,例如LineNumberTable, LocalVariableTable, SourceFile, Deprecated, Synthetic, Signature, and InnerClasses.

    -renamesourcefileattribute {string}    設(shè)置源文件中給定的字符串常量

    posted @ 2011-08-24 14:39 oathleo 閱讀(2505) | 評(píng)論 (0)編輯 收藏

    注意
    1.onDown 多指事件仍然響應(yīng)成單指
    2.onScroll滑動(dòng)時(shí)觸發(fā),e1只能獲得一個(gè)點(diǎn) ,而e2卻能獲得多點(diǎn)。(搞不清楚為什么怎么設(shè)計(jì))
    3.想在view上加 GestureListener
    可以使用下面的代碼:
    public class ViewerInnerTouchListener implements OnTouchListener {

        
    private GestureDetector gestureDetector;

        
    public ViewerInnerTouchListener(GAViewer viewer) {
            gestureDetector 
    = new GestureDetector(new GestureListener(viewer));
        }

        
    public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            
    return true;
        }

    }

        setOnTouchListener(
    new ViewerInnerTouchListener(this));

    判斷手勢(shì):
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Log.i(
    "onFling""onFling");
                
    return true// Right to left
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                
    return false// Left to right
            }
            
    if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                
    return false// Bottom to top
            } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
                
    return false// Top to bottom
            }
            
    return false;
        }


    GestureListener 的幾個(gè)方法要理解
         //Touch down時(shí)觸發(fā),不論是touch (包括long) ,scroll
         public boolean onDown(MotionEvent e) {
         return false;
         }
        
         //Touch了還沒(méi)有滑動(dòng)時(shí)觸發(fā)
         //(與onDown,onLongPress比較
         //onDown只要Touch down一定立刻觸發(fā)。
         public void onShowPress(MotionEvent e) {
         }
        
         //Touch了不移動(dòng)一直Touch down時(shí)觸發(fā)
         //Touchdown后過(guò)一會(huì)沒(méi)有滑動(dòng)先觸發(fā)onShowPress再是onLongPress。
         public void onLongPress(MotionEvent e) {
         }
        
         //上面這兩個(gè)函數(shù)都是在touch down后又沒(méi)有滑動(dòng)(onScroll),又沒(méi)有長(zhǎng)按(onLongPress),然后Touchup時(shí)觸發(fā)。
         /**
         * 點(diǎn)擊一下非常快的(不滑動(dòng))Touchup: onDown->onSingleTapUp->onSingleTapConfirmed
         *
         點(diǎn)擊一下稍微慢點(diǎn)的(不滑動(dòng))Touchup:onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed
         * 點(diǎn)擊longpress ,onScroll 時(shí) 不觸發(fā) onSingleTapUp
         */
         public boolean onSingleTapUp(MotionEvent e) {
         Log.i("onSingleTapUp", "onSingleTapUp");
         return false;
         }
        
         //Touch了滑動(dòng)時(shí)觸發(fā)
         public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
         float distanceY) {
         return true;
         }
        
         //Touch了滑動(dòng)一點(diǎn)距離后,up時(shí)觸發(fā)
         public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
         float velocityY) {
         return true;
         }

    posted @ 2011-08-21 11:59 oathleo 閱讀(3251) | 評(píng)論 (0)編輯 收藏

    之 前一直沒(méi)有搞懂a(chǎn)ndroid:padding和android:layout_margin的區(qū)別,其實(shí)概念很簡(jiǎn)單,padding是站在父view的 角度描述問(wèn)題,它規(guī)定它里面的內(nèi)容必須與這個(gè)父view邊界的距離。margin則是站在自己的角度描述問(wèn)題,規(guī)定自己和其他(上下左右)的view之間 的距離,如果同一級(jí)只有一個(gè)view,那么它的效果基本上就和padding一樣了

    posted @ 2011-08-18 16:33 oathleo 閱讀(318) | 評(píng)論 (0)編輯 收藏

    layout在xml里是無(wú)法使用findView 找到的

    只能使用:
    View menu = inflater.inflate(R.layout.main_left_layout, null);

    獲得
    LayoutInflater 的方法:
    1.Activity
    LayoutInflater inflater = getLayoutInflater(); 
    2.
    LayoutInflater inflater = LayoutInflater.from(context);



    posted @ 2011-08-16 12:53 oathleo 閱讀(235) | 評(píng)論 (0)編輯 收藏

    1、XML資源文件可以被AAPT打包進(jìn)應(yīng)用程序包,如果需要被打包,放置在/res/xml目錄下,如果不需要被打包,放置在/res/raw下。

    2、對(duì)/res/xml的支持

    以讀取/res/xml/test.xml為例

    Resources res=activity.getResources();

    XmlResourceParser xpp=res.getxml(R.xml.test);

    inet eventType=xpp.getEventType();

    再根據(jù)evenType的類(lèi)型,判斷讀取了什么內(nèi)容,比如說(shuō),讀到了文檔的開(kāi)頭,XmlPullParser.START_DOCUMENT等

    使用xpp.getName()取得標(biāo)志名稱(chēng),使用xpp.getText()取得文本內(nèi)容

    最后

    eventType=xpp.next();來(lái)讀取下一行內(nèi)容

    3、對(duì)/res/raw的支持

    以讀取/res/raw/test.txt為例

    Resources r=activity.getResources();

    InputStream is=r.openRawResource(R.raw.test);

    4、資產(chǎn)

    /assets不會(huì)在R.java中生成資源ID,必須指定文件路徑才能讀取它們。文件路徑是以/assets開(kāi)頭的相對(duì)路徑。

    AssetManger am=activity.getAssets();

    InputStream is=am.open("test.txt");

    posted @ 2011-08-08 11:24 oathleo 閱讀(492) | 評(píng)論 (0)編輯 收藏

         摘要: 在Android 2.3狀態(tài)欄中添加menu,home和back快捷鍵的方法 1、準(zhǔn)備資源,修改XML文準(zhǔn)備幾張圖,這里我們準(zhǔn)備添加home back和menu圖標(biāo),就需要準(zhǔn)備6張圖,三張普通狀態(tài),三張按下的高亮狀態(tài)圖標(biāo):stat_home.pngstat_home_pressed.pngstat_back.pngstat_back_pressed.pngstat_menu.pngstat_men...  閱讀全文

    posted @ 2011-08-05 15:45 oathleo 閱讀(1129) | 評(píng)論 (0)編輯 收藏

    和奇怪,調(diào)試模式下的SAX和script
    效率巨慢,而運(yùn)行模式下,好很多,大概快5-10倍。

    另外script包會(huì)編譯一個(gè)print方法,這個(gè)過(guò)程耗時(shí)很多,嚴(yán)重影響效率
    去掉并做些優(yōu)化后
    500條腳本,執(zhí)行從1s縮減到200ms

    代碼精簡(jiǎn)如下:
    RhinoScriptEngine.java
        Scriptable getRuntimeScope(ScriptContext ctxt) {
            
    if (ctxt == null) {
                
    throw new NullPointerException("null script context");
            }

            
    // we create a scope for the given ScriptContext
            Scriptable newScope = new ExternalScriptable(ctxt, indexedProps);

            
    // Set the prototype of newScope to be 'topLevel' so that
            
    // JavaScript standard objects are visible from the scope.
            newScope.setPrototype(topLevel);

            
    // define "context" variable in the new scope
            newScope.put("context", newScope, ctxt);

            
    // define "print", "println" functions in the new scope
            //去掉下面幾行
    //        Context cx = enterContext();
    //        try {
    //            cx.evaluateString(newScope, printSource, "print", 1, null);
    //        } finally {
    //            cx.exit();
    //        }
            return newScope;
        }

    posted @ 2011-08-03 14:18 oathleo 閱讀(1510) | 評(píng)論 (0)編輯 收藏

    僅列出標(biāo)題
    共17頁(yè): First 上一頁(yè) 4 5 6 7 8 9 10 11 12 下一頁(yè) Last 
    主站蜘蛛池模板: 亚洲免费在线观看| 最新亚洲卡一卡二卡三新区| 亚洲中文字幕无码爆乳| 午夜宅男在线永久免费观看网| 亚洲福利在线播放| 免费的黄色的网站| 亚洲国产午夜福利在线播放| 国产精品久久久久久亚洲影视| 99精品视频免费在线观看| 亚洲视屏在线观看| 在人线av无码免费高潮喷水| 国产成+人+综合+亚洲专| 免费精品一区二区三区在线观看| 亚洲视频一区在线观看| 一二三四视频在线观看中文版免费| 亚洲国产精品综合久久20| 在线观看人成视频免费| 直接进入免费看黄的网站| 国产午夜亚洲不卡| 日本在线免费播放| 久久乐国产精品亚洲综合| 久久99久久成人免费播放| 亚洲AV无码成人精品区在线观看 | 91视频免费网站| 亚洲国产成人一区二区三区| 91福利免费视频| 性xxxx黑人与亚洲| 亚洲成AV人在线观看网址| 美女被免费网站91色| 亚洲宅男永久在线| 免费国产成人高清在线观看网站| 亚洲欧洲日韩国产一区二区三区| 四虎成人精品在永久免费| 中文字幕免费在线看| 亚洲欧洲精品一区二区三区| 美女黄网站人色视频免费国产| jizz免费观看| 亚洲一本之道高清乱码| 免费二级毛片免费完整视频| 日本免费中文视频| 欧美日韩亚洲精品|