[Android] This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint


Android Error This view is not constrained vertically
This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint

If you get the above error in the activity XML file when trying to add an element in the UI say a Button or an EditText, well it's because you have not set the vertical or horizontal constraints. When you are on the design view you may also see the errors below,

❗️ Not Horizontally Contrained.
❗️ Not Horizontally Contrained.

Solution:
  1. Go to your activity.xml file,
  2. Move to Design View,
  3. Under Pallette, select Layouts -> ConstraintLayout,
  4. Now click on the wand icon -> Infer Constraint.
  5. You should see layout_margin Top and Right added to the XML and error is gone.
Before:
<Button
  android:id="@+id/button4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Button"
  tools:layout_editor_absoluteX="140dp"
  tools:layout_editor_absoluteY="316dp" />
After:
<Button
  android:id="@+id/button4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
 android:layout_marginStart="140dp"
  android:layout_marginTop="316dp"
  android:text="Button"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent" />
Check a visual GIF demo to make it easy to understand,
Solution This view is not constrained vertically
Solution This view is not constrained vertically
Advertisements
Try Out Code2care Dev Tools:

Advertisements



#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency