2011-07-18 139 views

回答

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(). 
+0

在onSensorChanged我想'view.layout(X,Y ,x + view.getWidth(),y + view.getHeight());'對於每個視圖,其中x和y是新的座標,並且視圖甚至不顯示... – jul

+0

注意x和y相對於家長。確保您的視圖寬度和高度不爲零。 –

+0

他們不是......佈局被調用時,l,t,r和b是正確的。但沒有顯示意見。我試圖使無效()父母,它不會改變任何東西... – jul

0

FrameLayout並不好做這樣的事情,與RelativeLayout你可以做到以下幾點:

RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)child.getLayoutParams(); 

layoutParams.leftMargin = x; 
layoutParams.topMargin = y; 

child.setLayoutParams(layoutParams);