我有一个带有TextView子元素的FrameLayout,我想在运行时更改TextViews的位置(在onSensorChanged()中,所以每秒几次)。没有setPosition(...),所以我该怎么做?
由于
答案 0 :(得分:0)
您需要的只是View.layout(int,int,int,int)
方法
Reference说:
public void layout (int l, int t, int r, int b) Since: API Level 1 Assign a size and position to a view and all of its descendants This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().
答案 1 :(得分:0)
FrameLayout
做这类事情并不好,RelativeLayout
您可以执行以下操作:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)child.getLayoutParams();
layoutParams.leftMargin = x;
layoutParams.topMargin = y;
child.setLayoutParams(layoutParams);