【发布时间】:2014-12-26 14:36:56
【问题描述】:
在我的项目中,我的布局如下:
<FrameLayout> ---------(1)
<SurfaceView>
<FrameLayout> ------(2)
</SurfaceView>
</FrameLayout>
我想访问框架布局(2)相对于框架布局(1)的位置/偏移量。
当我尝试 FrameLayout1.getLeft() 和 FrameLayout1.getTop() 时,我得到它为零。
获取嵌套元素(left,top) 的正确方法是什么?
谢谢!
更新--->
int dpi = getResources().getDisplayMetrics().densityDpi;
int offset1 = childFrameLayoutPosition[0] - rootFrameLayoutPosition[0]; //x offset
int offset2 = childFrameLayoutPosition[1] - rootFrameLayoutPosition[1]; //y offset
//F1 is child FrameLayout
newBitmap = Bitmap.createBitmap(bitmap,offset1*w, offset2*w,F1.getWidth()*w,F1.getHeight()*w);
执行此操作后,我得到了 Width 和 Height 参数应该小于位图的宽度和高度的错误。
【问题讨论】:
标签: android android-layout position android-ui