2012-09-21 28 views
0

爲什麼fragment的屬性爲class,但是ImageView沒有?爲什麼我們需要這個class屬性?例如,考慮:類屬性如何用於片段和常規視圖?

<fragment class="com.expample.testfragment.Title" 
     android:id="@+id/title" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
/> 

也:

<ImageView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Img1" 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:scaleType="fitXY" 
/> 

回答

0

爲什麼片段具有屬性class = 「」

你需要指定路徑(在包的形式,其中fragment類聲明和fragment類的實際名稱)表示佈局中的片段的類(因此係統可以instantia爲你的,建立UI等)。

但ImageView沒有?

您可以將其設置爲ImageView類屬性(或其他視圖),但它會被忽略,它不會作出任何意義有它,系統知道在哪裏可以找到視圖。

class屬性可以用來申報自定義視圖的佈局是這樣的:

<view class="package.here.to.custom.view.CustomView" <!-- other attributes --> /> 

,如果你有聲明爲另一個類嵌套類的自定義視圖這將是有益的。