Книга: Beginning Android

A Bit About Inflation

A Bit About Inflation

In this case, “inflation” means the act of converting an XML layout specification into the actual tree of View objects the XML represents. This is undoubtedly a tedious bit of code: take an element, create an instance of the specified View class, walk the attributes, convert those into property setter calls, iterate over all child elements, lather, rinse, repeat.

The good news is that the fine folk on the Android team wrapped all that up into a class called LayoutInflater that we can use ourselves. When it comes to fancy lists, for example, we will want to inflate Views for each row shown in the list, so we can use the convenient shorthand of the XML layout to describe what the rows are supposed to look like.

In the preceding example, we inflate the R.layout.row layout we created in the previous section. This gives us a View object that, in reality, is our LinearLayout with an ImageView and a TextView, just as R.layout.row specifies. However, rather than having to create all those objects ourselves and wire them together, the XML and LayoutInflater handle the “heavy lifting” for us. 

Оглавление книги

Оглавление статьи/книги

Генерация: 1.351. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз