Getting nearly crazy in creating the layout XML for phones. Maybe I was too long with Xcode or simply don't understand yet how to do it in the right way on Android.
I have played around with creating layouts for Size (small, normal, large, xlarge) and density, but nothing works.
I have a background for my screen, attached, and like to position the two input fields and the button over the layout. That works fine, using relative layout. But when running on devices, real or simulator, the fields are never right over the background. What am I doing wrong?
The XML for normal layout:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:src="@drawable/login2"
android:scaleType="fitXY" />
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/tfPass"
android:hint="CONTRASEÑA"
android:inputType="textPassword"
android:textColor="#000000"
android:background="#00000000"
android:singleLine="true"
android:layout_weight="1"
android:layout_x="3dp"
android:layout_y="342dp"
android:layout_alignTop="@+id/tfMail"
android:layout_marginTop="76dp"
android:layout_alignLeft="@+id/tfMail"
android:layout_alignStart="@+id/tfMail"
android:layout_alignRight="@+id/tfMail"
android:layout_alignEnd="@+id/tfMail" />
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/tfMail"
android:hint="EMAIL large"
android:textColor="#000000"
android:background="#00000000"
android:singleLine="true"
android:inputType="textEmailAddress"
android:layout_weight="1"
android:layout_x="3dp"
android:layout_y="287dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="353dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp" />
<ImageButton
android:layout_width="250dp"
android:layout_height="50dp"
android:id="@+id/btnLogin"
android:background="#00000000"
android:onClick="sel_Login2_login"
android:layout_weight="1"
android:layout_x="2dp"
android:layout_y="413dp"
android:layout_below="@+id/tfPass"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp" />
</RelativeLayout>
I preview witout action bar and in fullscreen. Also this i have in the manifest for the activity:
<activity
android:name=".Login2View"
android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and finally the background
UPDATE - full XML layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login2">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/tfPass"
android:hint="CONTRASEÑA"
android:inputType="textPassword"
android:textColor="#000000"
android:background="#00000000"
android:singleLine="true"
android:layout_weight="1"
android:layout_x="3dp"
android:layout_y="342dp"
android:layout_alignTop="@+id/tfMail"
android:layout_marginTop="55dp"
android:layout_alignLeft="@+id/tfMail"
android:layout_alignStart="@+id/tfMail"
android:layout_alignRight="@+id/tfMail"
android:layout_alignEnd="@+id/tfMail" />
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/tfMail"
android:hint="EMAIL normal"
android:textColor="#000000"
android:background="#00000000"
android:singleLine="true"
android:inputType="textEmailAddress"
android:layout_weight="1"
android:layout_x="3dp"
android:layout_y="287dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="255dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<ImageButton
android:layout_width="215dp"
android:layout_height="50dp"
android:id="@+id/btnLogin"
android:background="#00000000"
android:onClick="sel_Login2_login"
android:layout_weight="1"
android:layout_x="2dp"
android:layout_y="413dp"
android:layout_below="@+id/tfPass"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
UPDATE 03.11.2015
I will attach a screen shot from Android Studio. When using the same XML layout on different devices, the EditText and Button are misplaced. I have put a different background color for each. This is the result as shown in Android Studio and it looks the same on devices: