XML разметка для списка блюд.

Создаем XML разметку для списка блюд.
В этом посте напишем разметку для нашего списка блюд. Она будет включать два XML файла: dish.xml и dishitem.xml. С помощью первого файла мы сможем отобразить весь экран, на котором будет расположен наш список блюд, а с помощью второго файла мы зададим отображение отдельного элемента нашего списка, то есть конкретного блюда. 






Данные файлы должны быть расположены в папке res/layout нашего проекта.

Итак, вот код XML разметки файла dish.xml, он очень простой и содержит всего два элемента: RelativeLayout и ListView.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />

</RelativeLayout>


А вот код файла dishitem.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:padding="5px">


// здесь будет наша картинка

// не забываем использовать id, они нам еще понадобятся.
// id для ImageView  -  Image
<ImageView 
android:id="@+id/Image" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:paddingLeft="15px">

// название блюда

<TextView 
android:id="@+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"/>
// краткое описание блюда
<TextView 
android:id="@+id/ShortDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textStyle="italic"/>

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15px">

// масса блюда на выходе

<TextView  
android:id="@+id/Mass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"/>

// цена одной порции нашего блюда

<TextView  
android:id="@+id/Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"/>

</LinearLayout>
</LinearLayout>
</LinearLayout>

Комментарии, написанные в этом коде, в самих файлах должны отсутствовать, они здесь написаны для понимания.

Сохраняем оба файла под их именами, соответственно: dish и dishitem. Вот теперь у нас готова разметка для списка блюд. 

Комментариев нет:

Отправить комментарий