A. android中xml中有些控制項的屬性裡面有 "app:.." ,此處的app:是什麼意思和一般的android:有什麼區別
xmlns:Android=」http://schemas.android.com/apk/res/android」
xmlns:app=」http://schemas.android.com/apk/res-auto」
xmlns:cutstom="http://schemas.android.com/apk/res/com.example.customview"
android 和 app 都是xml 裡面的命名空間,android 是系統默認的,app是自定義的,你改成其它名字也可以,常用於自定義控制項的自定義屬性,res-auto會自動查找項目下的自定義屬性,也可以在後面跟上包名
--------------------
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<!--這里的name跟xmlns裡面的app沒關系,只是在自定義view裡面通過這個取自定義屬性-->
<declare-styleablename="CustomText">
<attrname="tsize"format="dimension"/>
<attrname="tcolor"format="color"/>
</declare-styleable>
</resources>
---------------------
xmlns:app=」http://schemas.android.com/apk/res-auto」
<com.example.customview.CustomTextView
app:tsize="5dp"
android:text="123"
>
</com.example.customview.CustomTextView>
B. android配置里的xml標簽——100分
你說的我也想看看,想知道都有啥.但是那個不是整個整個存在
你想知道的領域是什麼就去那裡找就有。
下面圖是關於LinearLayout的XMLAttributes。(一小部分)
圖的左下方的是widget里的東西,每個基本上都有XMLAttributes
想知道哪個方面就找哪個進去看看。Android官方網站就有
一段時間官方進不去,但是現在又可以了
http://developer.android.com
C. android里xml的標簽和類有什麼關系
setContentView的時候,會對布局xml文件進行解析,根據標簽的tag,將相對應類進行實例化。
一般view都會有上面幾個構造方法,第一個是用於在代碼中進行實例化的,其他構造方法是當view在xml里定義,系統解析時調用的方法,AttributeSet里存的就是你在xml里填寫的屬性
D. and android:解析xml,一個節點標簽中,有多個屬性,怎樣解析
定義好對象關系的類。
解析以Course為例子
java">publicstaticList<Course>getCourseList(InputStreamstream){
List<Course>list=newArrayList<Course>();
//得到DocumentBuilderFactory對象,由該對象可以得到DocumentBuilder對象
DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();
try{
//得到DocumentBuilder對象
DocumentBuilderbuilder=factory.newDocumentBuilder();
//得到代表整個xml的Document對象
Documentdocument=builder.parse(stream);
//得到"根節點"
Elementroot=document.getDocumentElement();
//獲取根節點的所有items的節點
NodeListitems=root.getElementsByTagName("item");
//遍歷所有節點
for(inti=0;i<items.getLength();i++){
Coursecourse=newCourse();
Elementitem=(Element)items.item(i);
course.setName(item.getAttribute("name"));
//再枚舉子節點
list.add(course);
}
}catch(ParserConfigurationExceptione){
e.printStackTrace();
}catch(SAXExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
returnlist;
}
E. android xml配置文件中一些標簽的作用
第一個xml是控制項動畫的xml,interpolator設置動畫播放的速度模型,這個設置的是播放速度逐漸變慢。第一個scale是縮放的動畫,ration是動畫時間,從0.9倍放大到1倍,pivot是指參照哪個點進行縮放,這個設置的50%是指中心。alpha是改變透明度的動畫,從0完全透明到1完全不透明。
第二個xml官方叫法是背景選擇器,就是改變按鈕之類的控制項在選中、獲得焦點及通常狀態時的背景的,可以是純色,也可以像你這個似的是drawable中的圖片。在選擇背景時從上到下找到第一個符合條件的為准,state_之類的是各種條件,pressed按下,focused獲得焦點,等等,最後一個item是表示默認條件即之前條件都不滿足時的背景。