5package org.qtproject.qt.android;
7import android.content.Context;
8import android.util.AttributeSet;
9import android.view.View;
10import android.view.ViewGroup;
11import android.view.ViewParent;
13class QtLayout
extends ViewGroup {
17 this(
context, View.generateViewId());
20 QtLayout(
Context context,
int viewId)
26 QtLayout(
Context context, AttributeSet attrs)
28 super(context, attrs);
29 if (getId() == View.NO_ID)
30 setId(View.generateViewId());
33 QtLayout(
Context context, AttributeSet attrs,
int defStyle)
35 super(context, attrs, defStyle);
36 if (getId() == View.NO_ID)
37 setId(View.generateViewId());
41 protected void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec)
43 int count = getChildCount();
49 measureChildren(widthMeasureSpec, heightMeasureSpec);
52 for (
int i = 0;
i <
count;
i++) {
53 View
child = getChildAt(i);
54 if (
child.getVisibility() != GONE) {
58 if (
child.getLayoutParams() instanceof QtLayout.LayoutParams) {
59 QtLayout.LayoutParams lp
60 = (QtLayout.LayoutParams)
child.getLayoutParams();
61 childRight = lp.x +
child.getMeasuredWidth();
62 childBottom = lp.y +
child.getMeasuredHeight();
64 childRight =
child.getMeasuredWidth();
65 childBottom =
child.getMeasuredHeight();
68 maxWidth = Math.max(maxWidth, childRight);
69 maxHeight = Math.max(maxHeight, childBottom);
74 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
75 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
77 setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
78 resolveSize(maxHeight, heightMeasureSpec));
88 protected ViewGroup.LayoutParams generateDefaultLayoutParams()
90 return new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
91 android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
97 protected void onLayout(
boolean changed,
int l,
int t,
int r,
int b)
99 int count = getChildCount();
100 for (
int i = 0;
i <
count;
i++) {
101 View
child = getChildAt(i);
102 if (
child.getVisibility() != GONE) {
103 QtLayout.LayoutParams lp =
104 (QtLayout.LayoutParams)
child.getLayoutParams();
106 int childLeft = lp.x;
108 int childRight = (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) ?
109 r - l : childLeft +
child.getMeasuredWidth();
110 int childBottom = (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) ?
111 b -
t : childTop +
child.getMeasuredHeight();
112 child.
layout(childLeft, childTop, childRight, childBottom);
119 protected boolean checkLayoutParams(ViewGroup.LayoutParams
p)
121 return p instanceof QtLayout.LayoutParams;
125 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams
p)
127 return new LayoutParams(
p);
135 static class LayoutParams
extends ViewGroup.LayoutParams
172 LayoutParams(ViewGroup.LayoutParams
source)
183 if (indexOfChild(
view) == -1)
186 detachViewFromParent(
view);
198 void setLayoutParams(
final View childView,
199 final ViewGroup.LayoutParams
params,
200 final boolean forceRedraw)
203 if (childView ==
null)
207 if (!checkLayoutParams(
params))
210 final ViewParent parent = childView.getParent();
213 final boolean canUpdate = (
this == parent);
216 childView.setLayoutParams(
params);
221 if (parent instanceof ViewGroup)
222 ((ViewGroup)parent).removeView(childView);
223 addView(childView,
params);
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
GLenum GLenum GLsizei count
GLboolean GLboolean GLboolean b
GLsizei GLsizei GLchar * source