Android orientation change causes ImageView to dissapear

Posted by Jarrod Smith on Stack Overflow See other posts from Stack Overflow or by Jarrod Smith
Published on 2011-11-12T09:32:00Z Indexed on 2011/11/12 9:50 UTC
Read the original article Hit count: 1057

Below is my layout for the row template in a SimpleCursorAdapter.

The ImageView with id next_arrow disappears on orientation change. If I replace @drawable/arrow with @drawable/icon (copy of the standard sym_def_app_icon) it works fine.

I thought it might be somehow related to the icons being of different dimensions, but I resized @drawable/icon to be the exact same dimensions as the arrow and it still worked fine while the arrow didn't.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="90dp"
              android:background="@drawable/product_list_divider"
              android:paddingTop="10dp">

    <ImageView android:src="@drawable/ninja_20_65"
               android:id="@+id/category_icon" 
               android:layout_marginLeft="20dp"
               android:layout_marginRight="20dp"
               android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="3dp"/>

    <LinearLayout android:orientation="vertical"
                  android:layout_weight="5"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content">

        <TextView android:id="@+id/category_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Name" 
            style="@style/CategoryHeading" android:layout_marginTop="5dp"/>
        <TextView android:id="@+id/category_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="Description"
            style="@style/CategoryDescription"/>
    </LinearLayout>

    <ImageView android:src="@drawable/arrow"
               android:layout_weight="1"
               android:layout_width="0dp"
               android:layout_marginRight="10dp"
               android:layout_height="wrap_content" android:layout_marginTop="20dp" android:id="@+id/next_arrow"/>

</LinearLayout>

© Stack Overflow or respective owner

Related posts about android

Related posts about android-layout