1

I'm pretty new to android studio and app designing and I'm facing some problems in designing an app.

I'm using relative Layout to set the position of different elements on a page but it is not working. I'm including my syntax and results below for your reference.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Quiz app"
        android:textSize="40dp"
        tools:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name: "
        android:textSize="20dp"
        tools:layout_below="@id/textView1"
        tools:layout_alignParentLeft="true"
        tools:layout_marginLeft="15dp"
        tools:layout_marginTop="40dp"
        />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password: "
        android:textSize="20dp"
        tools:layout_below="@id/textView2"
        tools:layout_alignParentLeft="true"
        tools:layout_marginLeft="15dp"
        tools:layout_marginTop="15dp"/>

    <EditText
        android:id="@+id/fillblank1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="name"
        android:textSize="20dp"
        tools:layout_below="@id/textView1"
        tools:layout_toRightOf="@id/textView2"
        tools:layout_marginLeft="50dp"
        tools:layout_marginTop="30dp"/>
</RelativeLayout>

But the result is coming as:

when I'm running the app

Device: on Nexus 6P API 27 Oreo

I did check out the other questions related to relative layout problems but I don't think they are as bad as this case so I asked this as a separate question.

h4kr
  • 238
  • 1
  • 3
  • 13

1 Answers1

2

Replace tools with android.

The 'tools' namespace is only used at design time and not at runtime. You can read more about it here

For example, instead of

tools:layout_centerHorizontal="true"

do

android:layout_centerHorizontal="true"
danartillaga
  • 1,349
  • 1
  • 8
  • 19