I want to add a custom view programatically over an activity and place it in bottom-center of the activity.
So far, I am able to create a view, set its X and Y coordinates and add it to the root view but I am unable to center align the view.
Is there any way to achieve this?
I do not want to use the XML to achieve this as I want to add the view dynamically.
I have tried to search StackOverflow for this but cant get anything to work.
This is how I am adding the view.
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mView = inflater.inflate(R.layout.view_popup_toast, null)
mView?.findViewById<TextView>(R.id.popup_text)?.text = "Text"
mView?.x = 500F
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
//This is not working
//params.gravity = Gravity.CENTER_VERTICAL or Gravity.BOTTOM
(window.decorView.rootView as ViewGroup).addView(mView, params)