Fixed
Status Update
Comments
ar...@gmail.com <ar...@gmail.com> #2
Came across same issue today, horizontal margins are not working when set through constraint set's connect method but vertical do...
ro...@obsi.com.au <ro...@obsi.com.au> #3
I've also encountered this bug.
dg...@gmail.com <dg...@gmail.com> #4
ConstraintSet.START and ConstraintSet.END work as expected, so that is one answer. ConstraintSet.LEFT and ConstraintSet.RIGHT continue to not work.
ro...@obsi.com.au <ro...@obsi.com.au> #5
That works dg! I'll use that for now. Did you just go through all the members of ConstraintSet to see what works?
Description
I expect each side of the TextView to have the specified margin set in ConstraintSet#connect.
Library used (support-v4, appcompat-v7, ...):
com.android.support:appcompat-v7:25.3.1
com.android.support.constraint:constraint-layout:1.0.2
Version used:
Theme used:
Theme.AppCompat.Light.DarkActionBar
Devices/Android versions reproduced on:
Emulator/API 24
Samsung S7/API 24
- Relevant code to trigger the issue.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
ConstraintLayout layout;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (ConstraintLayout) findViewById(R.id.constraint_layout);
TextView textView = new TextView(this);
textView.setId(View.generateViewId());
textView.setBackgroundColor(Color.RED);
textView.setGravity(Gravity.CENTER);
textView.setText("A text view");
layout.addView(textView);
ConstraintSet constraints = new ConstraintSet();
constraints.clone(layout);
constraints.constrainWidth(textView.getId(), ConstraintSet.MATCH_CONSTRAINT);
constraints.constrainHeight(textView.getId(), ConstraintSet.MATCH_CONSTRAINT);
constraints.connect(textView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID,
ConstraintSet.LEFT, 40);
constraints.connect(textView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID,
ConstraintSet.RIGHT, 40);
constraints.connect(textView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID,
ConstraintSet.TOP, 80);
constraints.connect(textView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID,
ConstraintSet.BOTTOM, 80);
constraints.applyTo(layout);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="
xmlns:tools="
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright"
tools:context="com.example.connectmargins.MainActivity" />
- A screenrecord or screenshots showing the issue (if UI related).