我有一个项目,我有两个挑战:
I have a project where I have 2 challenges:
第一:
将一个图标,只要手指触摸屏幕:对于这一点,最好的方法我发现,是使用 .layout()
方式的看法。
For this, the best approach I've found, is to use .layout()
method on the view.
二:
在我有两个布局,在 RelativeLayout的,都与屏幕宽度和高度(1背后隐藏的除外)。我想我每次点击一个按钮移到一个以上几个逢低权。 I have two layouts, on a RelativeLayout, both with screen width and height (1 is hidden behind the other). I want to move the one above a few dips to the right every time I click a button.有没有更好的方式来移动在Android上的看法?
还有什么能使用该方法的缺点 .layout()
What could be the disadvantages of using the method .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
在此先感谢。
Thanks in advance.
窗口管理器保持的LayoutParams
类的至少有两个以上的实例每个视图,除了一个在查看
本身。
WindowManager maintains at least two more instances of LayoutParams
class for each view, besides that one in the View
itself.
检查 updateViewLayout
窗口管理器
的方法,这部分特别是:
Check updateViewLayout
method of WindowManager
, this part in particular:
view.setLayoutParams(wparams);
synchronized (this) {
int index = findViewLocked(view, true);
ViewRoot root = mRoots[index];
mParams[index] = wparams;
root.setLayoutParams(wparams, false);
}
我相信,你可以通过布局
直接调用做一些乱七八糟。使用 WindowManager.updateViewLayout
代替。这会慢一些,但安全(只是IMO)。
I believe that you can make some mess by calling layout
directly. Use WindowManager.updateViewLayout
instead. It will be slower, but safe (just IMO).
更新
[来源: http://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);