Untitled
unknown
plain_text
a year ago
922 B
9
Indexable
RelativeLayout parentLayout = findViewById(R.id.parent_layout);
RelativeLayout childLayout1 = findViewById(R.id.child_layout_1);
RelativeLayout childLayout2 = findViewById(R.id.child_layout_2);
RelativeLayout childLayout3 = findViewById(R.id.child_layout_3);
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Bỏ lắng nghe để tránh tính toán lại nhiều lần
parentLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int width1 = childLayout1.getWidth();
int width2 = childLayout2.getWidth();
int width3 = childLayout3.getWidth();
int totalWidth = width1 + width2 + width3;
// Hiển thị hoặc sử dụng totalWidth
Log.d("TotalWidth", "Tổng chiều rộng của 3 RelativeLayout là: " + totalWidth);
}
});
Editor is loading...
Leave a Comment