Time of Update: 2013-12-10
螢幕大小1、不同的layout Android手機螢幕大小不一,有480x320,640x360,800x480.怎樣才能讓App自動適應不同的螢幕呢? 其實很簡單,只需要在res目錄下建立不同的layout檔案夾,比如:layout-640x360,layout-800x480,所有的layout檔案在編譯之後都會寫入R.java裡,而系統會根據螢幕的大小自己選擇合適的layout進行使用。2、hdpi、mdpi、ldpi
Time of Update: 2013-12-10
雖然前面都使用的View來進行繪圖,但View繪圖機制存在兩個缺陷:1、缺乏雙緩衝機制2、更新映像時,必須更新View上的整張圖片,效率低。所以在遊戲繪製中推薦使用SurfaceView。它可以只對指定地區進行更新,可以提高效率。下面用一個簡單樣本來示範SurfaceView的使用:Activity: package com.home.activity; import android.app.Activity; import android.graphics.Bitmap;
Time of Update: 2013-12-10
關於如何監聽裝置插拔以及擷取裝置許可權我就不說了,大家可以在網上搜一下有很多這方面的文章,我這裡就說一下如何讀寫資料。 UsbInterface usbInterface = usbDevice.getInterface(0); //USBEndpoint為讀寫資料所需的節點 UsbEndpoint inEndpoint = usbInterface.getEndpoint(0); //讀資料節點 UsbEndpoint outEndpoint =
Time of Update: 2013-12-10
public class CircleView extends View { private int maxProgress = 100; private int progress = 30; private int progressStrokeWidth = 4; //
Time of Update: 2013-12-10
Android音效SoundPool問題:soundpool 1 not retry 今天開發中要用到SoundPool,遇到soundpool 1 not retry無法播放聲音,MediaPlay可以 後來經過一番研究,發現:出現soundpool 1 not retry問題的代碼,無法播放聲音mgr = (AudioManager)
Time of Update: 2013-12-10
print?<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
Time of Update: 2013-12-10
SharedPreferences是Android平台上一個輕量級的儲存類,主要是儲存一些常用的配置比如視窗狀態,一般在Activity中 重載視窗狀態onSaveInstanceState儲存一般使用SharedPreferences完成,它提供了Android平台常規的Long長 整形、Int整形、String字串型的儲存。 在Fragment中的使用方法 @Override public void onCreate(Bundle
Time of Update: 2013-12-10
由於最近在做的一個遊戲項目有一個熱門排行榜, 熱門排行榜是一個列表,介面大致如下: 排名 人物名稱 頭像圖片 分數 排名 人物名稱 頭像圖片 分數 排名 人物名稱 頭像圖片
Time of Update: 2013-12-10
1.requestFocus() 擷取焦點模式2.PopuWidow 設定其動畫寫xml 補禎動畫,在style 樣式xml 檔案中寫<stye name="動畫名稱" ><item name="@android:windowEnterAnimation" >開啟動畫</item><item name="@android:windowExitAnimation"
Time of Update: 2013-12-10
在android手機上做自動化測試,monkey比cts,Android UnitTest 好用多了,他其實是繼承與adb
Time of Update: 2013-12-10
先看段關於android中動畫設定檔的虛擬碼:<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> &
Time of Update: 2013-12-10
在android的開發中,尤其是與訪問網路有關的開發,都要判斷一下手機是否串連上了網路,下面是一個判斷是否串連網路的嗲嗎片段:package cn.com.karl.util;import com.kubu.main.R;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import
Time of Update: 2013-12-10
GridView比ListView更容易實現自適應的表格,但是GridView每個格單元的大小固定,而ListView實現的表格可以自訂每個格單元的大小,但因此實現自適應表格也會複雜些(格單元大小不一)。另外,GridView實現的表格可以定位在具體某個格單元,而ListView實現的表格則只能定位在表格行。因此還是那句老話:根據具體的使用環境而選擇GridView 或者
Time of Update: 2013-12-10
SlideMenu項目依賴ActionBarSherlock這個開源項目,所以研究它需要下載兩個開源項目。使用Git分別為:SlideMenu:https://github.com/jfeinstein10/SlidingMenu.gitActionBarSherlock: https://github.com/JakeWharton/ActionBarSherlock.git 這次主要講解在學習該項目執行個體過程中經常遇到的錯誤,下次在講解具體案例。1
Time of Update: 2013-12-10
package com.zxl;import android.app.ListActivity;import android.os.Bundle;import android.view.View;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;public class MainActivity extends ListActivity { /**
Time of Update: 2013-12-10
關於如果和防止android 程式防止被360kill掉之後重啟的問題,肯定大家也搜尋了好多方法,都不好使,對不對,什麼增高許可權了,什麼進程優先順序了,這些東西都不是我們可控的,所以有沒有一些非常保險的方法,讓程式被kill掉之後自動重啟呢。 大家發現沒有,當我們使用360進行程式清理的時候,有些應用自己快速的啟動起來了,他們是怎麼實現的呢?其實我們沒有見過他們的源碼,也不好說是怎麼實現的。
Time of Update: 2013-12-10
一、計算文字的大小 String timeStr = "00:00"; int textWidth = (int)Layout.getDesiredWidth(timeStr, 0, timeStr.length(), tp);二、文字加粗 TextPaint tp = text.getPaint(); tp.setFakeBoldText(true);三、文字加底線 String str = "底線";
Time of Update: 2013-12-10
package cn.testforeground;import java.util.List;import android.os.Bundle;import android.app.Activity;import android.app.ActivityManager;import android.app.ActivityManager.RunningTaskInfo;import android.content.ComponentName;import
Time of Update: 2013-12-10
實現按鈕按下和釋放,按鈕背景圖片相應轉場效果的方法這裡介紹兩種,一種是在代碼裡實現,另一種是在xml檔案裡實現一、在xml檔案裡首先現在layout的一個xml檔案下定義Button如下所示: [html]<Button android:id="@+id/btn_user_selected"
Time of Update: 2013-12-10
package cc.testtipmessage1;import android.os.Bundle;import android.widget.ImageView;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Bitmap.Config;import android.graphics.BitmapFactory;