Jump to content

[semi-solved] Android Studio - XML looks nothing like the layout when emulated?

TheTurtleKing

So, uh, title explains it. 

 

Whenever I try to emulate my xml layout on a Pixel emulator, everything gets all bunched up.

what did I do wrong?

halp

 

 

android studio help.png

Link to comment
Share on other sites

Link to post
Share on other sites

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.turtle.testmed.MainActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sign_in"
        tools:layout_editor_absoluteX="172dp"
        tools:layout_editor_absoluteY="91dp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textEmailAddress"
        tools:layout_editor_absoluteX="72dp"
        tools:layout_editor_absoluteY="132dp"
        android:width="240dp"/>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        tools:layout_editor_absoluteX="72dp"
        tools:layout_editor_absoluteY="234dp"
        android:width="240dp"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Continue"
        tools:layout_editor_absoluteX="146dp"
        tools:layout_editor_absoluteY="355dp" />

</android.support.constraint.ConstraintLayout>
Link to comment
Share on other sites

Link to post
Share on other sites

42 minutes ago, TheTurtleKing said:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.turtle.testmed.MainActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sign_in"
        tools:layout_editor_absoluteX="172dp"
        tools:layout_editor_absoluteY="91dp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textEmailAddress"
        tools:layout_editor_absoluteX="72dp"
        tools:layout_editor_absoluteY="132dp"
        android:width="240dp"/>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        tools:layout_editor_absoluteX="72dp"
        tools:layout_editor_absoluteY="234dp"
        android:width="240dp"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Continue"
        tools:layout_editor_absoluteX="146dp"
        tools:layout_editor_absoluteY="355dp" />

</android.support.constraint.ConstraintLayout>

update: added

android:gravity="center"
android:layout_gravity="center"

to lines 8 and 9.

 

still no luck so I deleted those lines.

Link to comment
Share on other sites

Link to post
Share on other sites

Interesting observation....

 

I changed the theme to material dark but the emulator didn't change?

android studio help.png

Link to comment
Share on other sites

Link to post
Share on other sites

I somewhat solved it. 

I had to "infer constraints" on all of the stuff. more here

 

Still though, theme isn't really working.

 

 

android studio help.png

Link to comment
Share on other sites

Link to post
Share on other sites

The XML Source you posted had just the constraints for the correct rendering in the design view in Studio. It was missing the correct layout attributes like app:layout_constraint.... The constraint attributes prefixed with tools: just contain absolute positions for the layout editor. 

For your theme issue, try to change the theme inside your AndroidManifest.xml  and rebuild your project. This should solve your issue 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×