0

I got an XML file that includes a ConstraintLayout and inside this layout i got three views. The layout as its width set to "wrap_content" which automatically wrap it to the left side like this:

enter image description here

in the XML edit window, when i set layout_gravity to the right, it moves the layout to the right as expected:

enter image description here

I'm trying to achieve the same layout_gravity movement to right but programmatically (in Java) but i can not find any way to do it.

Abhinav Suman
  • 940
  • 1
  • 9
  • 29
Parkinson
  • 61
  • 1
  • 8
  • the wrap_content may cause the issue. try match_parent or some fix size (bigger than child views) to test. – Elias Fazel Feb 01 '20 at 18:50
  • What is your requirement? Please specify what all views do you need to display and be specific about there placement as well. – Nadeem Shaikh Feb 01 '20 at 19:23
  • If I understand correctly, this answer might work for you: [here](https://stackoverflow.com/a/2945763/11783376) – mushter Feb 01 '20 at 19:35
  • @mushter i tried it but it doesn't work because ConstraintLayout doesn't take a 3rd int argument like FrameLayout. – Parkinson Feb 01 '20 at 20:29
  • @NadeemShaikh I got a listview with this constraint layout for the items. i want some items to show on the right side of the listview while keeping others on the left, like in the snapshots i put here – Parkinson Feb 01 '20 at 20:32
  • did you find a solution? – Siddarth G Feb 04 '20 at 13:21
  • actually i did. i had to put this constraintview in another constraintview. than i was able to make the change. – Parkinson Feb 06 '20 at 06:01
  • You can check out this answer for any help. [Setting constraints programatically](https://stackoverflow.com/questions/45263159/constraintlayout-change-constraints-programmatically) – Puneet Sharma Nov 26 '21 at 10:10

0 Answers0