Android : How to programmatically set layout_constraintRight_toRightOf “parent”

Here is an example of setting a button to the bottom of parent view using java code: ConstraintLayout constraintLayout; ConstraintSet constraintSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); constraintLayout = (ConstraintLayout) findViewById(R.id.activity_main_constraint_layout); Button button = new Button(this); button.setText(“Hello”); constraintLayout.addView(button); constraintSet = new ConstraintSet(); constraintSet.clone(constraintLayout); constraintSet.connect(button.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.RIGHT, 0); constraintSet.constrainDefaultHeight(button.getId(), 200); constraintSet.applyTo(constraintLayout); } to … Read more

How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

Well, I saw the answer above and it worked for me too. But, I gave it a shot, and succeded converting my current project to Relative Layout. Do as follows: At activity_main.xml tab, change it to text. At the top of it, you’ll find the following: <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” Just change all before xmlns to RelativeLayout. … Read more

How to add different weight to ConstraintLayout views

In XML Create a horizontal chain, and then use the app:layout_constraintHorizontal_weight attribute: <?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” android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/one” android:layout_width=”0dp” android:layout_height=”48dp” android:background=”#caf” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toLeftOf=”@+id/two” app:layout_constraintHorizontal_weight=”6″/> <TextView android:id=”@+id/two” android:layout_width=”0dp” android:layout_height=”48dp” android:background=”#fac” app:layout_constraintLeft_toRightOf=”@+id/one” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintHorizontal_weight=”4″/> </android.support.constraint.ConstraintLayout> In Java Create your views and add them to the parent ConstraintLayout. You will need to give them … Read more

Android – how to make a scrollable constraintlayout?

It seems that it is working, I don’t know what dependency you were working with but in this one compile ‘com.android.support.constraint:constraint-layout:1.0.2’ Is working, this is what I did <?xml version=”1.0″ encoding=”utf-8″?> <ScrollView 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”> <android.support.constraint.ConstraintLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <android.support.design.widget.TextInputLayout android:id=”@+id/til_input” android:layout_width=”0dp” android:layout_height=”wrap_content” android:hint=”Escriba el contenido del archivo” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toLeftOf=”@+id/btn_save” app:layout_constraintTop_toTopOf=”@id/btn_save” app:layout_constraintVertical_chainStyle=”spread”> <EditText … Read more

Android Layout editor ConstraintLayout

Please check ConstraintLayout here: https://developer.android.com/training/constraint-layout/index.html When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints. However, this is only to make editing easier; if a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the … Read more

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

This layout works in my app. The trick is to set these two attributes in ScrollView: android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” The simplified layout from my app: <?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” android:theme=”@style/ThemeOverlay.AppCompat.Light”> <RelativeLayout android:id=”@+id/linear” android:layout_width=”0dp” android:layout_height=”56dp” android:background=”@color/title” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> <ScrollView android:layout_width=”0dp” android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”@id/linear”> <android.support.constraint.ConstraintLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:id=”@+id/titleView” … Read more

ConstraintLayout Chains and Text Ellipsis + Image on the Right

UPDATE JULY 2020: What does constrainedWidth/Height do? A lot of people kept asking me what exactly does this constrainedWidth/Height do when set to true (defaults to false). I finally have an answer (from a Google employee), so in lieu of clearing up all the doubts people coming to this post keep having, here’s what I … Read more

Travis CI failed because cannot accept license Constrain Layout

Updated response is there any solution without workaround using export license? Yes, you can use the new sdkmanager to install the constraint library and accept the license: – echo yes | sdkmanager “extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2” – echo yes | sdkmanager “extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2” Otherwise, the missing component will be detected by gradle and downloaded without accept it: # Show … Read more

How to achieve overlap/negative margin on Constraint Layout?

Update ConstraintLayout now supports negative margins with version 2.1.0-alpha2. Simply state android:layout_marginTop=”-25dp” for a negative 25dp margin. (This will only work if the top of the view is constrained. A margin has no effect in ConstraintLayout if the margin’s side is not constrained.) Clarification: The answer below remains valid, but I want to clarify a … Read more