1

enter image description here

Button Doesn't appear in xml even after infer constraints is used.

enter image description here

enter code here
<?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=".MainActivity"
    tools:layout_editor_absoluteY="25dp">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="133dp"
        tools:layout_editor_absoluteY="253dp" />
</android.support.constraint.ConstraintLayout>
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
anup davda
  • 15
  • 5

3 Answers3

0

It seems your button is missing horizontal/vertical constraints.

Try changing your button constraint like this.

 <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="133dp"
        tools:layout_editor_absoluteY="253dp" />

And run your activity/fragment is a device/emulator. Even if that doesn't show up button, there is issue rendering button over the design view of the Android Studio. Try changing API version in editor.

Sushant Somani
  • 1,450
  • 3
  • 13
  • 31
0

Relative positioning is one of the basic building block of creating layouts in Constraint Layout. Those constraints allow you to position a given widget relative to another one. Check out the documentation here for clear understanding :

Constraint Layout

As for your question, Try to replace this code with your button code

     <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        />
Sabin Acharya
  • 493
  • 4
  • 9
0
<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

it makes this button center of your activity.

read the documentation for more further detail. Link -here

SK Panchal
  • 47
  • 11