新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > Android常見錯誤匯總

        Android常見錯誤匯總

        作者: 時間:2016-10-08 來源:網絡 收藏

        16.交互性的button定義的方法:

        首先是準備好按鈕不同狀態的圖片

        然后 在res/drawable中定義selector的xml文件

        最后Button的background屬性中設置

        android:id=@+id/btnAdd

        android:layout_width=wrap_content

        android:layout_height=wrap_content

        android:background=@drawable/addbtn_selector/>

        17在超級終端中執行程序報錯-Permission deny

        參照http://android.stackexchange.com ... fo-on-error-message

        主要原因是不能在sdcard中執行,直接進入data/目錄下面創建文件,然后執行就可以了。

        18.從svn導入工程項目有驚嘆號

        錯誤提示Archive for required library: 'libs/armeabi/libvudroid.so' in project 'DocumentViewer' cannot be read or is not a valid ZIP file

        主要是路徑出了問題

        解決方法:在project的build-path將外部包(庫)的引用刪掉就可以了。

        19.首次進入帶有EditText的Activity不自動彈出軟鍵盤,再次點擊才彈出。

        只有設置manifest的方法有用,在activity的設置中添加:

        [html] view plaincopyprint?

        android:windowSoftInputMode=adjustPan|stateHidden

        20.Gallery中OnItemClickListener與OnItemSelectedListener的區別

        OnItemClickListener:只有單擊Gallery中的View才會觸發事件,準確的說是當點擊之后抬起手的時候觸發,滑動不會觸發。

        OnItemSelectedListener:當Gallery中的View被選中的時候就會觸發,Galler初次顯示就會觸發一次,選中第一個iew,滑動和單擊都會觸發。

        20.從16進制中提取顏色的rgb分量。

        主要就是通過位運算來實現。

        [java] view plaincopyprint?

        public class Main {

        public static void main(String[] args) {

        // TODO Auto-generated method stub

        int INK_COLOR = 0xFF11ef23;

        float r = getColorR(INK_COLOR );

        float g = getColorG(INK_COLOR );

        float b = getColorB(INK_COLOR );

        System.out.print(r+ +g+ +b);

        }

        public static float getColorR(int c)

        {

        int R = (c 0x00FF0000 )>>16;

        return (float) (R/255.0);

        }

        public static float getColorG(int c)

        {

        int G =(c 0x0000FF00 )>>8;

        return (float) (G/255.0);

        }

        public static float getColorB(int c)

        {

        int B = c 0x000000FF;

        return (float) (B/255.0);

        }

        }

        21. Eclipse中簽名導出apk崩潰,手動簽名。

        工程沒問題,調試也沒問題,但打包的時候eclipse會崩潰,解決方法是手動打包。

        首先去工程目錄下的bin文件夾下找到apk文件,解壓后刪除META-INF文件夾,重新打包成壓縮包,改后綴名為.apk

        首先是簽名(假設你已經在根目錄下生產了密鑰keystore):

        進入java安裝目錄/bin文件夾下:

        [plain] view plaincopyprint?

        ./jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore android.keystore ~/Output.apk android

        然后是優化,進入sdk的tools文件夾下,運行。

        [plain] view plaincopyprint?

        ./zipalign -v 4 ~/Output.apk Output_realase.apk

        當前目錄下Output_realase.apk就是打包簽名好的apk了。

        22.android.view.InflateException: Binary XML file line #異常的解決

        創建自定義view的時候,碰到 android.view.InflateException: Binary XML file line #異常,反復研究

        后發現是缺少一個構造器造成。

        [java] view plaincopyprint?

        public MyView(Context context,AttributeSet paramAttributeSet)

        {

        super(context,paramAttributeSet);

        }

        補齊這個構造器,異常就消失了.

        23.將assets文件夾中的壓縮包拷貝到sdcard中(不限大小)

        [java] view plaincopyprint?

        public static void copyAssetToSdcard(Context c, String assetFile, String destination) throws IOException {

        InputStream in = c.getAssets().open(assetFile);

        File outFile = new File(destination);

        OutputStream out;

        Log.v(Try, Try coping.);

        try {

        if (!(new File(destination)).exists()) {

        Log.v(Try, Not exists..);

        out = new FileOutputStream(outFile);

        copyFile(in, out);

        in.close();

        in = null;

        out.flush();

        out.close();

        out = null;

        }

        } catch (Exception e) {

        Log.v(Error, Error in if。);

        }

        }

        public static void copyFile(InputStream in, OutputStream out) throws IOException {

        Log.v(Coping, copyFiling.);

        byte[] buffer = new byte[1024];

        int read;

        while ((read = in.read(buffer)) != -1) {

        Log.v(read:, + read);



        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 恩平市| 天等县| 临武县| 贵南县| 延吉市| 文成县| 苏尼特右旗| 凤山县| 嘉禾县| 绥棱县| 花垣县| 黄大仙区| 同仁县| 丰台区| 克山县| 巴青县| 阿拉善盟| 托克托县| 色达县| 丰台区| 甘洛县| 莱州市| 龙门县| 宜宾县| 天全县| 青阳县| 五寨县| 宕昌县| 洛扎县| 绍兴市| 徐水县| 洪江市| 尼勒克县| 凭祥市| 台北市| 正定县| 镇江市| 蒙山县| 施秉县| 酉阳| 团风县|