Java method for android:layout_gravity

前端 未结 6 2052
别跟我提以往
别跟我提以往 2020-12-03 21:07

I would like to know if is there a way to call android:layout_gravity property from a Java method. I didn\'t found any method in Android documentation to do it.

6条回答
  •  不思量自难忘°
    2020-12-03 21:41

    Well as far as I understand you looking for this It is for FrameLayout for other layout see appropriate LayoutParams classes. For setting gravity like in your XML use something like:

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.LEFT | Gravity.CENTER_VERTICAL)
    

    followed by addView with newly constructed LayoutParams

提交回复
热议问题