假设我有一个视图结构<ConstraintLayout> <CustomViewLayout> ... ... </CustomViewLayout></ConstraintLayout>这是简化的,但我在底部工作表中使用了上面的内容,有时我会ConstraintLayout根据我的CustomViewLayout身高改变底部工作表的高度和透视高度。我的问题是,如果部分CustomViewLayout被切断,也就是说 - 它有点在屏幕之外,因为ConstraintLayout它不够高 - 我不再能够获得正确的“全高”。在这种情况下,我似乎总是只能在视图的屏幕上看到可见部分。那么我怎样才能获得部分不在屏幕上的视图的全高呢?谢谢!编辑:我应该补充一点,我尝试过的是 a globalLayoutListener,以及 a customViewLayout.post {}(customViewLayout.height当然也是通常的)。但是当部分视图在屏幕之外时,这些都没有测量完整高度。
2 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
如果您正在寻找视图宽度和高度,请尝试以下操作:
mCustomViewLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mCustomViewLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int height = mCustomViewLayout.getMeasuredHeight()
int width = mCustomViewLayout.getMeasuredWidth()
}
});
添加回答
举报
0/150
提交
取消