Change the Right Margin of a View Programmatically?

后端 未结 4 2105
野性不改
野性不改 2020-11-30 18:04

Can this attribute be changed dynamically in Java code?

android:layout_marginRight

I have a TextView, that has to change its

4条回答
  •  攒了一身酷
    2020-11-30 18:41

    Use LayoutParams (as explained already). However be careful which LayoutParams to choose. According to https://stackoverflow.com/a/11971553/3184778 "you need to use the one that relates to the PARENT of the view you're working on, not the actual view"

    If for example the TextView is inside a TableRow, then you need to use TableRow.LayoutParams instead of RelativeLayout or LinearLayout

提交回复
热议问题