Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app:layout_marginBottom is not working well with android constraint layout

Is there any reason why the following layout_marginBottom is not working? However, if I use layout_marginTop on the second view it does work well

<android.support.constraint.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#ade4ad">     <TextView         android:id="@+id/first"         android:layout_width="90dp"         android:layout_height="40dp"         app:layout_marginBottom="10dp"         android:background="#000"/>     <TextView         android:id="@+id/second"         android:layout_width="90dp"         android:layout_height="40dp"         android:background="#fff"         app:layout_constraintTop_toBottomOf="@+id/first"/> </android.support.constraint.ConstraintLayout> 
like image 284
Ron____ Avatar asked Jul 05 '17 16:07

Ron____


People also ask

Can we use Relativelayout inside ConstraintLayout?

You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

What purpose does a ConstraintLayout have within Android applications?

ConstraintLayout provides you the ability to completely design your UI with the drag and drop feature provided by the Android Studio design editor. It helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code.

How do I change ConstraintLayout?

Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.

What is ConstraintLayout widget barrier?

androidx.constraintlayout.widget.Barrier. Added in 1.1. A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.

What is constraintlayout in Android?

ConstraintLayout is similar to that of other View Groups which we have seen in Android such as RelativeLayout, LinearLayout, and many more. In this article, we will take a look at using ConstraintLayout in Android. This is used to give a unique id to the layout.

What is the difference between constraints layout and grid layout in Android?

In Grid Layout, the UI which is actually seen in the Design editor of Android Studio will be the same as that we will get to see in the app, but in the case of Constraint layout if the UI component is not Constrained then the UI will not look same as that of in design editor.

How to get margin between two textview in Android?

This is not LinearLayout or RelativeLayout, its ConstraintLayout so you have to give Left, Right, Bottom, Top Constraint to Relevant Layout, in your case You have to give TextView first Bottom_Top Constraint to TextView second. so you can get Margin between Two TextView. Your layout should be like below.

How do I use constraintlayout in the layout editor?

All the power of ConstraintLayout is available directly from the Layout Editor's visual tools, because the layout API and the Layout Editor were specially built for each other. So you can build your layout with ConstraintLayout entirely by drag-and-dropping instead of editing the XML.


1 Answers

In order to

android:layout_marginBottom="20dp"  

work well, you should use

app:layout_constraintBottom_toBottomOf="parent" 
like image 107
Ucdemir Avatar answered Sep 17 '22 21:09

Ucdemir