我有一个项目,面临两个挑战:
First:
为此,我发现的最好的方法是使用.layout()
视图上的方法。
Second:
- 我有两个布局,一个相对布局,都有屏幕宽度和高度(1 隐藏在另一个后面)。每次单击按钮时,我都想将上面的那个向右移动几次。
Android 上有更好的移动视图的方法吗?
使用该方法可能有什么缺点.layout()
?
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
Parameters:
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent
提前致谢。
WindowManager 至少还维护两个实例LayoutParams
除了视图中的那个视图之外,每个视图的类View
itself.
Check updateViewLayout
的方法WindowManager
,这部分特别是:
view.setLayoutParams(wparams);
synchronized (this) {
int index = findViewLocked(view, true);
ViewRoot root = mRoots[index];
mParams[index] = wparams;
root.setLayoutParams(wparams, false);
}
我相信你可以通过打电话来制造一些混乱layout
直接地。使用WindowManager.updateViewLayout
反而。它会更慢,但安全(仅在我看来)。
UPDATE
[From: https://stackoverflow.com/a/11188273/327011 ]
WindowManager windowsManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)
WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.x = <new X coord>;
windowParams.y = <new Y coord>
windowParams.height = myImageView.getHeight();
windowParams.width = myImageView.getWidth();
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowParams.format = PixelFormat.TRANSLUCENT;
windowParams.windowAnimations = 0;
windowManager.updateViewLayout(myImageView, windowParams);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)