![](/img/trans.png)
[英]Adjust height of two ImageView with equal width according to screen height with ContraintLayout
[英]Get Height and Width of a child layout in contraintlayout
我有一個約束布局,其中有一個子布局(frame_layout)。 使用match_constraint將寬度和高度設置為0dp。 一旦在屏幕上加載了布局,我們如何獲得這個frame_layout的高度和寬度? 使用layoutparams給出0dp。 getWidth或getHeight再次給出0dp。
final FrameLayout layout = (FrameLayout) findViewById(R.id.YOUR_VIEW_ID);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.