Padding and margin in a layout

Hi everyone,

I'm facing a serious issue right now, and I don't know if I'm just doing it bad or if it's a bug.

I want a page in landscape mode, split in 2 parts. On the right part I have a linear layout and I want everything in it with an horizontal padding of 48dp. Simple right ?

So there is my axml file : (look at the last linear layout)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/logo_est_rescue" />
            <ImageView
             android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/txt_est_rescue" />
        </LinearLayout>

        <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:paddingHorizontal="48dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Connexion"
                android:textSize="20sp"
                android:textStyle="bold"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="48dp" />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="hello1"
                android:singleLine="true"/>
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="hello2"
                android:singleLine="true"/>
        </LinearLayout>

My preview is exactly what I want :

However, when I run it on my tablette or on the emulator, the padding doesn't work :

Did I make a mistake ? Thx !

Best Answer

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @NicolasFournier

    That's odd, did you try setting the margins for the two EditText controls?

  • NicolasFournierNicolasFournier Member ✭✭

    @JGoldberger

    I try to remove the padding for the linear layout and move it to the EditText. To the testing purpose, I try one with layout_marginHorizontal (what I want) and one with paddingHorizontal (I don't wan't that, just for testing).

    The code : (last linear layout)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
            <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5">
                <ImageView
                    android:layout_width="180dp"
                android:layout_height="180dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="48dp"
                    android:src="@drawable/logo_est_rescue"
                    android:id="@+id/imageView1" />
                <ImageView
                    android:layout_width="300dp"
                    android:layout_height="180dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/txt_est_rescue" />
            </LinearLayout>
            <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Bienvenue"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="72dp"
                    android:layout_marginBottom="48dp" />
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="hello1"
                    android:singleLine="true"
                    android:layout_marginHorizontal="48dp"/>
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="hello2"
                    android:singleLine="true"
                    android:paddingHorizontal="48dp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Mot de passe oublié ?" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Connexion"
                    android:theme="@style/CustomButton"
                    local:MvxBind="Click ConnectionCommand" />
            </LinearLayout>
    </LinearLayout>
    

    The preview look OK :

    But on the emulator... :

    I don't know what to do :/

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
Sign In or Register to comment.