android


How do I use ConstraintSet in Android to stack TextViews horizontally?


I've been looking around for a couple days now on how to add and constain TextViews programmatically, and for some reason I cannot get it to work. I've looked at other answers and the recommended order in which you should go about adding constraints, however this did not work for me.
With my current solution, the TextViews stack up like this. My aim was to have it seperated like this.
My current code looks like this:
// Get all the existing assignments and list them
Assignment[] currentAssignments = Assignment.getAssignments();
// Get the layout that will hold the assignments
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.mainLayout);
// Loop through each assignment, creating a TextView and getting information for each one
for (int i = 0; i < currentAssignments.length; i++) {
// Create new TextView and set properties
TextView newTextView = new TextView(this);
newTextView.setId(i);
newTextView.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT));
newTextView.setText(currentAssignments[i].getAssignmentName() + "\nHand in date: " + currentAssignments[i].getAssignmentHandInDate());
newTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
// Add to layout
layout.addView(newTextView);
}
// Set up a new ConstraintSet so we can constrain all the assignments
ConstraintSet set = new ConstraintSet();
// Clone the current layout
set.clone(layout);
// Loop through previously added assignments in layout and connect them
for (int i = 0; i < layout.getChildCount(); i++) {
// Setup new constraints to place on screen properly
if (i > 0) {
// If assignment is not the first to be added, link it to the previously added assignment
set.connect(i, ConstraintSet.TOP, i - 1, ConstraintSet.BOTTOM, 8);
}
else {
// If the assignment is the first to be added link it to the top of the layout
set.connect(i, ConstraintSet.TOP, layout.getId(), ConstraintSet.TOP, 8);
}
}
// Apply changed layout to actual layout
set.applyTo(layout);
My question:
How do I layout TextViews horizontally in a ConstraintLayout, programmatically?
Thank you for reading!

Related Links

Which structure should I use at firebase?
How to create create multiple folders to store images for a single user in firebase [closed]
List all users with webservice Restful in Android
Espresso - Clicking menu item with app:showAsAction=“ifRoom”
Delete row in Custom Listview using SQLITE
Android Bluetooth Le scanner stops after a time
openFileActivityBuilder intent. How to wait for it to connect and how to get the file out of it
'maps' in google.maps.LatLngBounds() shows “Cannot resolve symbol maps”
How to contact Google Play?
Xamarin Unable to create Intent
Android MediaBox framebuffer format
how to pass images and texts of alist view from one activity to another through bundle?
How do I convert translate this Picasso code into Glide?
gaps between item in recyclerview increasing while list updating dynamically and repeatedly android
Openlayers 3 unable to fire click event on Android mobile phone
How to set a static distance when initialize the maps api on android

Categories

HOME
3d
jelastic
jsf-2.2
rds
android-json
vert.x
trac
nstableheaderview
flume
spin
pattern-matching
resultset
why3
mxgraph
ycsb
screen-readers
internationalization
production
swagger-2.0
boost-icl
undertow
squashfs
gulp-watch
hta
draft-js-plugins
froala
motion-detection
licensing
subclass
cppreference
browser-sync
autodesk-designautomation
mockjax
database-comparison
activexobject
hunspell
fiware-cygnus
imagenet
graphhopper
android-augmented-reality
sim-card
portforwarding
uiimage
dapper-simplecrud
vaadin-elements
libgphoto2
opennms
lampp
hammer.js
geotiff
bluez
compiler-design
git-flow
jqchart
bbpress
monkey
autosar
appscale
nss
phpwebsocket
libav
piracy-prevention
inf
avisynth
text-search
canalyzer
eoferror
vacuum
nutiteq
rrule
at-job
showdialog
jbake
browserify-shim
encryption-asymmetric
gii
alternate
sbcl
notorm
asdf
server-administration
apache-whirr
jsr286
apache-commons-dbutils
entitydatasource
w3c-geolocation
cdonts
drupal-fivestar
addchild
zen
blender-2.49
murmurhash
sun
cldc
blind

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile