Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Why does View background draw in editor but not in app?
    text
    copied!<p>I have an Android project with an xml file representing a row for an Adapter. </p> <p>This row has a coloured View on the left hand side. </p> <p>For some reason the View renders correctly in the graphical editor in Eclipse but not when I run it on a device. </p> <p>The View draws at the correct size but there's no blue background like the editor has. </p> <hr> <p>I've noticed when I dump the UI hierarchy that the View nodes aren't in the hierarchy. </p> <p>If I break on binding the views in the adapter, I can see that mMeasuredHeight is correct but mMeasuredWidth is 0. I feel like I'm missing something fundamental. </p> <hr> <p>Attached are screenshots and the xml file. </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;View android:id="@+id/view_header_accent" android:layout_width="50dp" android:layout_height="match_parent" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@color/blue_primary" /&gt; &lt;TextView android:id="@+id/txt_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="@dimen/grid_small" android:layout_marginTop="@dimen/grid_small" android:layout_toLeftOf="@+id/img_cancel" android:layout_toRightOf="@+id/view_header_accent" android:text="Brad" android:textSize="18sp" /&gt; &lt;TextView android:id="@+id/txt_subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/txt_title" android:layout_alignRight="@+id/txt_title" android:layout_below="@+id/txt_title" android:paddingBottom="@dimen/grid_small" android:text="Active" android:textColor="#80000000" android:textSize="14sp" /&gt; &lt;ImageView android:id="@+id/img_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="@dimen/grid_small" android:src="@drawable/ic_cancel" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Screenshot from graphical editor in Eclipse:</p> <p><img src="https://i.stack.imgur.com/KXP8e.png" alt="Screenshot from editor"></p> <p>Screenshot from device: </p> <p><img src="https://i.stack.imgur.com/xG2Rn.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload