0

I am having huge problems with the Android XML layout previewer not giving anywhere close to an accurate representation of my XML layout. The layout appears just fine when run, it's just the previewer.

Here's some example XML:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/sign_up_accountexists"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="You already have an account. Please sign in, or select &apos;forgot password&apos;."
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffffff" />

    <LinearLayout
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sign_up_accountexists"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Sign In" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Forgot Password" />

    </LinearLayout>

    <TextView
        android:id="@+id/sign_up_differentaddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Sign up using a different address"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffffff" />

</RelativeLayout>

Here the LinearLayout with the buttons is clearly below the sign_up_accountexists, and that's how it's shown when the program is run. But Eclipse shows:

[Buttons]

[sign_up_accountexists]

[sign_up_differentaddress]

The really odd thing is that if I remove _differentaddress the other two flip round correctly. It would be really helpful to get the previewer working.

So my question is twofold, (1) Is there anything I'm doing wrong in my XML which could trip up the previewer? (2) Do people generally use the previewer anyway? It's a great idea, but if generally known to be buggy then I will (reluctantly) avoid it.

One note: the LinearLayout has android:layout_below="@+id/sign_up_accountexists". Eclipse put that plus sign in there, which I thought was wrong. Removing it makes no difference though.

Many thanks in advance for answering a question which is consuming all my living hours...

HughHughTeotl
  • 5,439
  • 3
  • 34
  • 49

2 Answers2

1

I'm not sure how many others use the previewer but I tend to stay away from it, so it's up to. But wouldn't the LinearLayout have to be below the "@+id/sign_up_differentaddress"? I'm pretty sure it's just the way you've laid it out (ie. not putting the layout_below attributes in the right place). So probably just experimenting with the attributes might help, and try removing attributes and slowly adding them.

David Liaw
  • 3,193
  • 2
  • 18
  • 28
  • Thanks lonehangman! I've tried moving the elements around (3 elements => 6 possible orders, so tried them all) - to no avail. If I remove `_differentaddress` altogether, the other two elements flip round on screen. – HughHughTeotl Jun 25 '13 at 07:44
  • Probably a long shot but email be your code (If you want) and I'll see what is happening. – David Liaw Jun 25 '13 at 15:11
  • Really appreciate the offer ... but unfortunately can't email code as it's commercial. Interestingly I imported the project under Eclipse in Linux and got a completely different preview again: this time the buttons had disappeared entirely and only the TextViews were visible. I've kinda concluded that the preview is just buggy and I'm not using it. My life is about 100% more calm now. – HughHughTeotl Jun 25 '13 at 15:34
  • Yeah I understand your reasons, but yeah the UI builders are a bit 'touchy' and it's probably better to just use XML since you have more control over it. – David Liaw Jun 26 '13 at 01:01
0

I've faced issues like this before ! Infact if my xml contains an editText , the preview is not shown atall !! I switched to Android studio. Its just amazing !

Prachi
  • 3,584
  • 2
  • 24
  • 39
  • Hmm, interesting - thanks for the comment. Certainly prefer to stick with Eclipse as I have a million other projects in it (and apart from apparent ADT bugs it's an awesome SDK). I'll take a look at Android Studio though. – HughHughTeotl Jun 25 '13 at 07:15