Прежде всего, нет необходимости использовать ConstraintLayout , вы можете использовать LinearLayout в качестве родительского макета.
Затем с целью отображения всех Кнопки в одной строке, вы должны установить вес для LinearLayout в XML и установить вес для представлений, которые вы добавляете в него.
Файл xml должен выглядеть следующим образом:
<LinearLayout
android:id="@+id/TilesContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="5"
app:layout_constrainedWidth="true"
android:orientation="horizontal">
</LinearLayout>
И в коде вы должны установить вес для каждого просмотра, добавив , 1.0f к LayoutParam:
Context context = this;
LinearLayout layout = (LinearLayout) findViewById(R.id.TilesContainer);
LayoutParams params = new LayoutParams( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,1.0f );
params.setMargins(50, 50, 0, 0);
for (int i=0;i<wordLength;i++) {
Button tileButton = new Button(this);
tileButton.setLayoutParams(params);
tileButton.setText(wordStringtoLetters[i]);
tileButton.setId(i);
tileButton.setBackgroundResource(R.drawable.tile_button);
tileButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 36);
layout.addView(tileButton);
}