EditText centered in Xamarin, but not on device

SiflouSiflou USMember ✭✭

Hey guys,

I have a EditText in a LinearLayout and I put the editText, height to wrap content and its gravity to center. In Xamarin, I see it centered, but when i put it on device, theres an orange square when I select my edit text, and it isnt centered like it was in Xamarin. Anybody have an idea ? Thanks a lot !

Claude

Posts

  • TeHaTeHa DEMember ✭✭✭

    I do not even see the EditText in Xamarin centered.
    But you can host the EditText within a relativeLayout an set layout_centerInParent to true

  • SiflouSiflou USMember ✭✭

    I just tried it, and like the previous case, I see it centered in Xamarin, but on device it isnt centered. Does some one have an explanation for this.

  • StevenTheEvenStevenTheEven SEMember ✭✭✭

    Post your code.

  • TeHaTeHa DEMember ✭✭✭

    Now I've tried it and it seems as if wrap_content has no effect and the EditText is always match_parent. But you can set the cursor (and the text) with gravity="center"

  • SiflouSiflou USMember ✭✭

    Hey guys, so my code is : gonna try the TeHa's solution. Keep up with the suggestions, well get it :)

    <?xml version="1.0" encoding="utf-8"?>















  • SiflouSiflou USMember ✭✭

    <?xml version="1.0" encoding="utf-8"?>















  • SiflouSiflou USMember ✭✭

    <?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:background="@drawable/Background_SplashScreen"> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/rlForgotPasswordContent"> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/llForgotPasswordContent" android:layout_gravity="bottom" android:layout_centerInParent="true"> <ImageView android:id="@+id/imgLogoForgotPassword" android:background="@drawable/Splash_Logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="20dp" /> <TextView android:text="@string/yourPasswordWillBeSent" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/lblSendPassword" android:textColor="#ff797979" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" /> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:id="@+id/llEmail" android:background="@drawable/WhiteSpace_Simple_Email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="15dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:background="@drawable/Ico_Mail" android:padding="0dp" android:paddingTop="0dp" android:paddingRight="0dp" android:paddingBottom="0dp" android:paddingLeft="0dp" android:layout_marginLeft="10dp" android:layout_marginTop="13dp" /> <RelativeLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="fill_parent" android:id="@+id/relativeLayout1" android:layout_gravity="center"> <EditText android:id="@+id/txtEmail" android:text="@string/email" android:textColor="#ff757575" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_centerVertical="false" /> </RelativeLayout> </LinearLayout> <Button android:text="@string/submit" android:id="@+id/btnSubmit" android:background="@drawable/BtnSignup" android:textColor="#ffffffff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="25dp" /> <Button android:text="@string/cancel" android:id="@+id/btnCancelSubmit" android:textColor="#fff67638" android:background="#ffeaeaeb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="20dp" android:layout_marginBottom="20dp" /> </LinearLayout> </RelativeLayout> </LinearLayout>

  • StevenTheEvenStevenTheEven SEMember ✭✭✭

    Why do you have the first LinearLayout? I'm not sure what you are trying to do eventually. But my advice to you is to keep it as simple as you can. You ar mixing Linear/RelativeLayout all over the place ;) Maybe you have to but when i look at the result of it it looks like you have done it much more compicated then you have to. But i'm new to this also so this is only a first impression.

  • TeHaTeHa DEMember ✭✭✭

    @StevenTheEven: You're right. The first Layout is totally useless (and a few attributes) but the rest of the layout is needed.

    @Claude.6593: I think it's an android problem that you can't center a view that has a variable size. Because in the moment you click in the textview (the hint isn't visible anymore) android calculate a width of 0, because the view has no content. (maybe that's the reason, but I don't know)

Sign In or Register to comment.