技巧

1.res/values/color.xml 定義顏色
android:background="@color/gray"  引用顏色
2.尺寸換算 dp圖形 sp是文字
3.Nine-Patch圖片方法
\android\sdk\tools\draw9patch.bat
4.讀取Xml
  在res目錄下建立xml
  
  
  
  
    
    
    
    
     
     
     
     
  1. (0));
5.尺寸
在320x480分辨率,像素密度爲160,1dp=1px
在480x800分辨率,像素密度爲240,1dp=1.5px
3.實現下邊框 View注意大小寫
<View
android:layout_width="match_parent"
android:layout_height="1dp"
/>

 
<?xml version="1.0" encoding="utf-8"?><npcs> <npc name="令狐沖"> <base info="abc"> <level>5</level> </base> </npc></npcs>private void readSaveNpcsXML()throws Exception{ Resources res=getResources(); XmlResourceParser xrp=res.getXml(R.xml.npcs); List<Npc> npcs=new ArrayList<Npc>(); Npc npc=null; //判斷是否到了文件的結尾 while (xrp.getEventType()!=XmlResourceParser.END_DOCUMENT){ if(xrp.getEventType()==XmlResourceParser.START_TAG){ if(xrp.getName().equals("npc")) { npc=new Npc(); npc.setName(xrp.getAttributeValue }else if(xrp.getName().equals("base")){ //會遍歷到根下的全部屬性 } }else if(xrp.getEventType()==XmlResourceParser.END_TAG){ npcs.add(npc); npc=null; } xrp.next(); } }


相關文章
相關標籤/搜索