Alg*_*gar 7 java android android-view kotlin
假设我有一个类似的视图结构
<ConstraintLayout>
<CustomViewLayout>
...
...
</CustomViewLayout>
</ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是简化的,但我在底部使用上面的内容,我有时ConstraintLayout根据我的CustomViewLayout身高改变底部的高度和底部的高度.我的问题是,如果部分CustomViewLayout被切断,那就是 - 它有点在屏幕之外,因为ConstraintLayout它不够高 - 我不再能够获得正确的"全高".在这种情况下,我总是只看到视图屏幕上的可见部分.
那么如何才能获得部分偏离屏幕的视图的全高?
谢谢!
编辑:
我应该补充一点,我尝试的是一个globalLayoutListener,以及一个customViewLayout.post {}(customViewLayout.height当然通常).但是当视图的一部分位于屏幕之外时,这些都不会测量整个高度.
如果您正在寻找视图的宽度和高度,请尝试以下操作:
mCustomViewLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mCustomViewLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int height = mCustomViewLayout.getMeasuredHeight()
int width = mCustomViewLayout.getMeasuredWidth()
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
293 次 |
| 最近记录: |