Страница 1 из 1

Извлечь разметку из xml-файла

Добавлено: 13 фев 2014, 06:28
samodelkin
Имеется вот такая разметка:

Код: Выделить всё

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/game_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/left_engine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="левый двигатель"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button
android:id="@+id/right_engine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="правый двигатель"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
также имеется в активности такой код:
RelativeLayout rl= (RelativeLayout) this.findViewById(R.id.game_layout);
setContentView(rl);
при запуске приложение завершается, почему?

Re: Извлечь разметку из xml-файла

Добавлено: 13 фев 2014, 06:54
klblk
samodelkin писал(а):Имеется вот такая разметка:

Код: Выделить всё

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/game_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/left_engine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="левый двигатель"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button
android:id="@+id/right_engine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="правый двигатель"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
также имеется в активности такой код:
RelativeLayout rl= (RelativeLayout) this.findViewById(R.id.game_layout);
setContentView(rl);
при запуске приложение завершается, почему?
Вы пытаетесь найти там где ничего нет, и поставить то что нашли туда где искали.

Re: Извлечь разметку из xml-файла

Добавлено: 17 фев 2014, 16:09
парень
setContentView(R.layout."имя xml файла")
Уже потом мы обращаемся к эллементам.