How can I align an element to the right in the FrameLayout?

后端 未结 6 1418
挽巷
挽巷 2021-01-03 21:48

I have a FrameLayout which contains 2 views , the second is something like a Close Button (X) and i want to position it on the right.

I\'ve tried layout

6条回答
  •  别那么骄傲
    2021-01-03 22:20

    Programatically, you can set the margin using FrameLayout.LayoutParams. The following would work to place a view on the bottom of your screen:

    int desired_height_of_content = //whatever your want the height of your view to be
    FrameLayout layout = new FrameLayout(this);
    FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, desired_height_of_content);
    int difference = screen_height - desired_height_of_content
    flp.setMargins(difference, 0, 0, 0);
    layout.addView(your_view, flp);
    

提交回复
热议问题