The misalignment of your swap currency button is likely due to inconsistent margins and constraints between the Spinner elements and the MaterialButton. Here's how you can fix the issue:
Problem Explanation:
Inconsistent Margins: You have set layout_marginEnd="8dp" on spinner_from and both layout_marginStart="8dp" and layout_marginEnd="8dp" on button_swap, but no margins on spinner_to. This causes the button to shift towards one side, making it appear "crooked".
Constraints and Chain Style: The constraints between the spinners and the button need to be set up to distribute space evenly. Using a horizontal chain without specifying the chain style can lead to unexpected layouts.
Solution:
Remove or Equalize Margins:
To ensure the elements are evenly spaced, you can either remove the margins between spinner_from, button_swap, and spinner_to or make sure they are consistent across all components.
Set Up a Horizontal Chain:
Create a horizontal chain among the three views (spinner_from, button_swap, and spinner_to) by connecting their start and end constraints appropriately.
Specify Chain Style:
Use app:layout_constraintHorizontal_chainStyle="spread_inside" to distribute the available space evenly among the views in the chain.
Updated Code:
Replace your existing spinners and swap button code with the following:
Placing this attribute on spinner_from ensures the horizontal chain distributes extra space evenly between the spinners and the button.
Result:
With these changes, your swap button will be centered between the two spinners, and the layout will appear evenly spaced and aligned, fixing the "crooked" appearance.
Additional Tips:
Consistent Margins:
If you prefer to have margins, make sure to add equal margins to all components involved in the chain to maintain symmetry.
Chain Styles:
Experiment with different chain styles (spread, spread_inside, packed) and biases (app:layout_constraintHorizontal_bias) to achieve the desired layout behavior.
Testing:
After making changes, always test your UI on different screen sizes and orientations to ensure it behaves as expected.