我已經看過很多關於android的通貨膨脹的帖子,我還是不明白。有人能詳細描述它是什麼,爲什麼我需要它?他們說它創建了一個XML代碼以外的對象,並且可以被使用或者其他的東西。我幾乎瞭解其他所有事情,但這對我來說沒有意義。在android中充氣
回答
基本上是爲了讓你的邏輯部分不同於你的UI部分XML概念的出現。
1-以XML格式創建用戶界面非常簡單明瞭。
2 - 通過這種隔離,我們有選項來創建用於土地/肖像/小/正常/放大模式不同的UI ......
在運行時的XML只得到解析,並從創建對象那。
在Android中的LayoutInflator負責解釋的XML佈局像這樣:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ticketWeb"
/>
</RelativeLayout>
和從XML它將「膨脹」或在XML實例的每個項目的一個Java對象表示的屬性佈局。所以如果你有一個帶有這個xml文件的項目,那麼充氣機會創建你可以通過使用findViewById()來獲取的java對象。一旦你檢索到這些對象的引用,你可以調用它們的各種方法來影響關於它們的不同事情。
啊,非常感謝 –
在Android程序結構中使用了MVP即視圖處理演示者和設計即佈局xml。所以我們需要通過定義其他佈局來定義xml的邏輯,並經常用於維護UI操作,即改變UI行爲。因此,通過通貨膨脹將佈局xml加載到相應的視圖對象中進行操作,從而使我們很容易。
通過通貨膨脹我們可以訪問相應的UI到視圖對象。這個每個人都知道。 考慮活動課
class Activity1 extends Activity{
setContentView(R.layout.Mainlayout);
//here we are inflating the
//view into objects actually
//its is defined in earlier version as
//setContentView(getInflater().inflater(R.layout.MainLayout)
Button b=(Button)findViewById(R.id.button1);
}
的情況,但如果你寫
class Activity1 extends Activity{
Button b=(Button)findViewById(R.id.button1);//if called then there will be no errror but form runtimeexception Because of absence of setContext()
}
因此,對於類派生的每個UI,我們需要通脹但事實是,Android的廠商已經將通貨膨脹中的setContentView(),addview等這樣的初學者無法理解通貨膨脹是簡單的,但需求的理解 我們可以簡單的寫,如果button.xml只有按鈕
Button b=(Button)getInflater().inflate(R.layout.button);
- 1. 充氣視圖android
- 2. 在Android中回收充氣佈局
- 3. 在Android中獲取充氣異常
- 4. 無法在Android中充氣OptionsMenu
- 5. 在Android中充氣自定義控件
- 6. 行動欄不充氣 - android
- 7. Android錯誤充氣視圖
- 8. 錯誤充氣類的Android
- 9. Android ListView佈局充氣器
- 10. android ViewPager xml充氣錯誤
- 11. Android充氣tabcontent內的framelayout
- 12. Android刪除佈局充氣
- 13. Android - 將TabHost充氣到TabHost
- 14. ClassCastException當充氣Android片段
- 15. Android充氣標籤視圖
- 16. Java/Android充氣城堡ClassNotFoundException
- 17. 發生Android充氣異常
- 18. 錯誤充氣類com.google.ads.Adview Android
- 19. 充氣佈局的Android
- 20. 在充氣
- 21. 從Android中的OnClickListener充氣ListView行?
- 22. 錯誤充氣類Android中的按鈕
- 23. Android中的佈局充氣器
- 24. Android中的錯誤充氣菜單
- 25. 錯誤的xml正在充氣android
- 26. 充氣在Android的形狀層列表
- 27. Android在充氣後查找視圖
- 28. 在抽屜中充氣xml
- 29. 在Runnable中充氣資產
- 30. Android:使用它的android充氣listview:id
如果您不知道Android中的通貨膨脹是什麼意思,您如何理解Android UI? – JoxTraex
@ JoxTraex而不是評論通過編寫一個 答案使他明白。 –