Guest User

Untitled

a guest
Nov 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class ItemView extends ConstraintLayout {
  2. LinearLayout linearButtons;
  3. LinearLayout linearText;
  4. public ItemView(Context context, String name, String price, ArrayList<String> guests,
  5. ArrayList<String> checked, int id) {
  6. ...
  7. addView(linearText);
  8. addView(linearButtons);
  9. set.clone(this);
  10. set.connect(linearText.getId(), ConstraintSet.LEFT, this.getId(),
  11. ConstraintSet.LEFT, 8);
  12. set.connect(linearText.getId(), ConstraintSet.TOP, this.getId(),
  13. ConstraintSet.TOP, 8);
  14. set.connect(linearButtons.getId(), ConstraintSet.RIGHT, this.getId(),
  15. ConstraintSet.RIGHT, 8);
  16. set.connect(linearButtons.getId(), ConstraintSet.TOP, this.getId(),
  17. ConstraintSet.TOP, 8);
  18. }
  19.  
  20. for (Item it:r.getItems()) {
  21. ItemView itemView = new ItemView(this, it.getName(), nf.format(it.getPrice()), dinerlist, it.getGuests(), i);
  22. ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);
  23. itemView.setLayoutParams(params);
  24. vg.addV[enter image description here][1]iew(itemView);
  25. Log.d("ItemView Children: ", itemView.getWidth()+" "+itemView.getHeight());
  26.  
  27. //add the view with 0dp width and height
  28. val layoutParams = ConstraintLayout.LayoutParams(0, 0)
  29. val view = View(context)
  30. view.id = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) View.generateViewId() else 1138
  31. parent.addView(view)
  32.  
  33. //apply the default width and height constraints in code
  34. val constraints = ConstraintSet()
  35. constraints.clone(parent)
  36. constraints.constrainDefaultHeight(view.id, ConstraintSet.MATCH_CONSTRAINT_SPREAD)
  37. constraints.constrainDefaultWidth(view.id, ConstraintSet.MATCH_CONSTRAINT_SPREAD)
  38. constraints.applyTo(parent)
Add Comment
Please, Sign In to add comment