Phil Culver Phil Culver - 1 month ago 14
Android Question

Widgets not displaying properly in design view?

I am learning Android Studio for the first time and I'm stuck trying to run a program on a physical android device. The problem I'm having is that none of my content (widgets, textview, buttons) appear on the screen on my device. Is there something wrong with the computer I'm using? I can see and manipulate widgets in the editor but a lot of the things on screen I create don't show up in the correct spot except on the blueprint.

I've attached images of everything so you guys can take a look. I'm running this on an AMD A10- 9600p Radeon R5.
Thanks for the help.

<?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:ignore="MissingConstraints">

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
tools:ignore="UnknownId"
tools:layout_editor_absoluteY="42dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
android:layout_marginLeft="16dp" />

<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/editText"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView2"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toRightOf="@+id/textView2"
android:layout_marginLeft="16dp"
tools:ignore="UnknownId"
android:text="Hello this is my first app and I have no clue what I'm doing! Hopefully this all works out! I just need a bunch of words so i can create scorolling i am just typing things as fast as i can its problaly mispselled but who realy gives a hooot! just like the pokemon. this comupuete is decent but the bang for the buck is where its at. I caould make raps for fday s but its ok oops i guess i need some more word so this lovely app can scroll like a bouss hog out of the kitchen i think ill go get some ice cream soon yes great idea mr culver holla at ur boy yes"
app:layout_constraintBottom_toTopOf="@+id/button3"
android:layout_marginBottom="16dp"
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintVertical_bias="0.8"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
android:layout_marginRight="16dp" />

<Button
android:text="CANCEL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
tools:ignore="UnknownId"
tools:layout_editor_absoluteY="436dp"
tools:layout_editor_absoluteX="268dp" />

<Button
android:text="OK"
android:layout_width="88dp"
android:layout_height="48dp"
android:id="@+id/button3"
app:layout_constraintRight_toLeftOf="@+id/button2"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
tools:ignore="UnknownId"
app:layout_constraintBaseline_toBaselineOf="@+id/button2" />
</android.support.constraint.ConstraintLayout>


Image from Android Device

Android Studio Screenshot

Answer

It seems that a lot of your widgets actually do not have constraints. Remove the tools:ignore="MissingConstraints" attribute to see the missing ones. Every widget needs to be constrained at least with two constraints (one for the vertical axis, one for the horizontal axis).

Things display correctly in the layout editor simply because it's much nicer to keep the widgets where you put them while you are designing things, even if they don't have constraints. But on device, those fixed positions are not used.

Comments