Я написал приложение для Android с пользовательским интерфейсом на основе узла вкладок, состоящего из 3 вкладок. Каждая вкладка состоит из некоторых элементов пользовательского интерфейса, в основном текстовых и графических представлений.
Проблема, с которой я сталкиваюсь, заключается в следующем: при первом запуске приложение работает нормально. Если я не переключаю вкладки, просто нажмите кнопку «Назад», чтобы закрыть приложение, а затем снова запустите его, все работает нормально. Если я переключусь на другую вкладку и вернусь к первой, а затем нажму «назад», чтобы закрыть приложение, - когда я снова запущу его, первое представление вкладки будет повреждено. Это означает, что одно из изображений, которые я использую в качестве фона представления, не появляется, и вместо этого я получаю несколько серых горизонтальных линий с черным фоном вдоль всего представления. Представления всех других вкладок (которые используют то же изображение, что и фон, кстати) выглядят нормально. Все последующие исполнения приложения остаются поврежденными.
Это также непоследовательное поведение, не связанное с конкретным фоновым изображением, которое я использую (это все еще происходит, даже когда я полностью удаляю его из приложения). Еще одна вещь, которую я пробовал, - это переключаться между первым (проблемным) представлением вкладок и вторым. Когда я это сделал, проблема больше не повторялась.
Мне кажется, проблема в генерации кода файла R.java, но я понятия не имею, что не так.
Кто-нибудь знает, в чем проблема и как ее решить?
Спасибо.
Это XML активности основной вкладки:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.mycompany.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/main_bg">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
Это XML поврежденного представления:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TextView
android:id="@+id/TextTitle"
android:text="@string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="5sp"
android:paddingBottom="5sp"
android:textColor="@color/pink"
android:textStyle="bold"
android:textSize="18sp"
/>
<ImageView
android:src="@drawable/silver_line"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/star_bg"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
/>
<ImageView
android:src="@drawable/pink_lights"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:background="@color/transparent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LayoutSelectImage"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:text="@string/select_image"
android:id="@+id/TextSelectImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:minHeight="28sp"
android:textColor="@color/white"
android:textSize="19sp"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="10sp"
android:gravity="center_vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20sp"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/ImageCamera"
android:src="@drawable/icon_camera_reg"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:text="@string/camera"
android:id="@+id/TextCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textStyle="bold"
android:textSize="13sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/ImageGallery"
android:src="@drawable/icon_gallery_reg"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:text="@string/gallery"
android:id="@+id/TextGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textStyle="bold"
android:textSize="13sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/LayoutSelectGender"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="gone">
<TextView
android:text="@string/select_gender"
android:id="@+id/TextSelectGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="28sp"
android:textColor="@color/white"
android:textSize="19sp"
/>
<!--android:layout_weight="10"-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:gravity="center_vertical">
<!--android:layout_weight="60"-->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20sp"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/ImageFemale"
android:src="@drawable/icon_female_reg"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:text="@string/female"
android:id="@+id/TextFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textStyle="bold"
android:textSize="13sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/ImageMale"
android:src="@drawable/icon_male_reg"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:text="@string/male"
android:id="@+id/TextMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textStyle="bold"
android:textSize="13sp"
/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/ImageSelected"
android:background="@drawable/frame_pink_large"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1"
android:layout_margin="7sp"
android:padding="6px"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/LayoutLoading"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="gone">
<TextView
android:text="@string/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="28sp"
android:textColor="@color/white"
android:textSize="19sp"
/>
<ImageView
android:id="@+id/ImageLoading"
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15sp"
android:layout_marginBottom="25sp"
/>
<ImageView
android:id="@+id/ImageSelected2"
android:background="@drawable/frame_pink_large"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="7sp"
android:padding="6px"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/LayoutShow"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:visibility="gone">
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3sp">
<ImageView
android:id="@+id/ImageStripLeft"
android:src="@drawable/strip_left"
android:scaleType="fitCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/LayoutOriginal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:text="@string/original"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6sp"
android:layout_marginBottom="3sp"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="14sp"
android:shadowColor="@color/black"
android:shadowDy="1.2"
android:shadowRadius="1"
/>
<ImageView
android:id="@+id/ImageOriginal"
android:background="@drawable/frame_gray_large"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:padding="6px"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/LayoutOther"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:text="@string/other"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6sp"
android:layout_marginBottom="3sp"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="14sp"
android:shadowColor="@color/black"
android:shadowDy="1.2"
android:shadowRadius="1"
/>
<ImageView
android:id="@+id/ImageOther"
android:background="@drawable/frame_pink_large"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:padding="6px"
/>
</LinearLayout>
<ImageView
android:id="@+id/ImageStripRight"
android:src="@drawable/strip_right"
android:scaleType="fitCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/TextPercentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|top"
android:background="@drawable/strip_center"
android:paddingTop="2sp"
android:textColor="@color/pink"
android:textStyle="bold"
android:textSize="26sp"
android:shadowColor="@color/white"
android:shadowDy="1.2"
android:shadowRadius="1"
/>
</AbsoluteLayout>
<TextView
android:id="@+id/TextOther"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/pink"
android:textStyle="bold"
android:textSize="16sp"
/>
<ImageView
android:id="@+id/ImageShare"
android:src="@drawable/icon_share_reg"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10sp"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ImageResultsBackground"
android:src="@drawable/results_bg"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="@string/more_results"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15sp"
android:gravity="center"
android:textColor="@color/white"
android:textSize="16sp"
android:visibility="gone"
/>
<com.mycompany.myapp.Results.ResultsGallery
android:id="@+id/Gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:spacing="20sp"
/>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
РЕДАКТИРОВАТЬ: Тааак странно! Решение состояло в том, чтобы удалить два места в поврежденном XML-файле представления, где я определил фон «@color/transparent», где «прозрачный» — это цветовой ресурс со значением «# 00000000».
Теперь мой вопрос - почему???
Это правильный вид: http://imgur.com/dEz1G
А это поврежденный: http://imgur.com/CF25i.jpg а>
setBackgroundDrawable
илиsetBackgroundResource
- person Daniel Trebbien   schedule 31.01.2011