I’ve been having an issue which is extremely odd to me. The graphic I’m using is sometimes centered, for reasons I can’t understand, but only on certain displays. The top graphic is the bad example, the bottom one is the one I’d like to have. It seems to not be Android version dependent, both the good and bad were replicated on Android 1.6, and the bad was replicated on 2.1. It seems to only be size dependent…


relevant XML code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<com.google.ads.AdView android:id="@+id/adView"
ads:loadAdOnCreate="true" ads:adSize="BANNER"
ads:adUnitId="@string/admob_unit_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" ></com.google.ads.AdView>
<pearsonartphoto.AJEG.number_pad android:id="@+id/numberpad"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="@id/adView"
android:layout_centerHorizontal="true"></pearsonartphoto.AJEG.number_pad>
<pearsonartphoto.AJEG.Level_Score_bar android:id="@+id/Score_Bar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"></pearsonartphoto.AJEG.Level_Score_bar>
<ImageView android:id="@+id/logo_image"
android:layout_below="@id/Score_Bar"
android:layout_above="@id/numberpad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/level_logo"
android:layout_alignParentLeft="true"
android:layout_centerInParent="false"
android:gravity="left"></ImageView>
<TextView android:id="@+id/number_select"
android:layout_above="@id/numberpad"
android:layout_below="@id/Score_Bar"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/numberSelect"
android:layout_centerHorizontal="true"
android:gravity="center"></TextView>
<pearsonartphoto.AJEG.number_viewer android:id="@+id/numberviewer"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Score_Bar"></pearsonartphoto.AJEG.number_viewer>
</RelativeLayout>
As you can see, I’ve clearly set the gravity of the image to left, told it to align with Parent left, yet for some unknown reason it wants to align center.
I managed to solve the question by a bit of trickery that I had to put in for a different reason. It works, however, to solve two problems with one stone.
Basically, my ImageView became this:
The key bit was the line
android:layout_toLeftOf="@id/number_select", forced the image to not overlap with the textView with the number. It’s not perfectly to the left, but they at least don’t overlap, so I’m saying good enough for now.