-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Implment maxWidth and maxHeight in FrameLayout
-> Implement maxWidth and maxHeight -> Implement FlowLayout
- Loading branch information
1 parent
7f6c168
commit ac8d6be
Showing
5 changed files
with
135 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<LinearLayout | ||
<FrameLayout | ||
width="match_parent" | ||
height="wrap_content" | ||
paddingBottom="8dp" | ||
orientation="horizontal" | ||
padding="10dp" | ||
background="#AAA"> | ||
background="#AAA" | ||
gravity="center"> | ||
|
||
<LinearLayout | ||
width="match_parent" | ||
height="wrap_content" | ||
layoutGravity="center|top" | ||
maxWidth="1024dp"> | ||
|
||
<Button | ||
width="match_parent" | ||
height="wrap_content" | ||
orientation="vertical" | ||
padding="10dp" | ||
background="#555" | ||
gravity="center"> | ||
|
||
margin="5dp"/> | ||
<Button | ||
width="256dp" | ||
height="32dp" | ||
margin="5dp" | ||
text="OK"/> | ||
|
||
<TextView | ||
width="256dp" | ||
height="32dp" | ||
margin="5dp" | ||
text="OK"/> | ||
|
||
<EditText | ||
width="256dp" | ||
height="32dp" | ||
margin="5dp" | ||
text="OK"/> | ||
|
||
<Switch | ||
margin="5dp" | ||
text="OK"/> | ||
|
||
<ImageView | ||
width="128dp" | ||
height="128dp" | ||
margin="5dp" | ||
src="@drawable/default_window_icon" | ||
text="OK"/> | ||
|
||
<FrameLayout | ||
width="256dp" | ||
height="256dp" | ||
background="#A00"> | ||
<Button | ||
width="128dp" | ||
height="128dp" | ||
layoutGravity="center|bottom" | ||
margin="10dp"/> | ||
</FrameLayout> | ||
|
||
<CardLayout | ||
width="256dp" | ||
height="256dp" | ||
marginBottom="90dp" | ||
radius="16dp"> | ||
|
||
<View | ||
width="256dp" | ||
height="256dp" | ||
background="#000"/> | ||
|
||
</CardLayout> | ||
width="match_parent" | ||
height="wrap_content" | ||
margin="5dp"/> | ||
<Button | ||
width="match_parent" | ||
height="wrap_content" | ||
margin="5dp"/> | ||
<Button | ||
width="match_parent" | ||
height="wrap_content" | ||
margin="5dp"/> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package br.nullexcept.mux.widget; | ||
|
||
import br.nullexcept.mux.app.Context; | ||
import br.nullexcept.mux.graphics.Point; | ||
import br.nullexcept.mux.res.AttributeList; | ||
import br.nullexcept.mux.view.Gravity; | ||
import br.nullexcept.mux.view.View; | ||
import br.nullexcept.mux.view.ViewGroup; | ||
|
||
public class FlowLayout extends ViewGroup { | ||
private int dividerSize = 16; | ||
public FlowLayout(Context context) { | ||
super(context); | ||
} | ||
|
||
public FlowLayout(Context context, AttributeList attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
protected Point getChildLocation(View view) { | ||
int width = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); | ||
int height = getMeasuredHeight(); | ||
int y = 0; | ||
int x = 0; | ||
boolean find = false; | ||
int lineCount = 0; | ||
int w = 0; | ||
int mh = 0; | ||
for (int i = 0; i < getChildrenCount(); i++) { | ||
View child = getChildAt(i); | ||
if (child.getMeasuredWidth() + w > width) { | ||
if (find) break; | ||
if (lineCount == 0) { | ||
mh = Math.max(mh, child.getMeasuredHeight()); | ||
if (child.equals(view)) { | ||
w = child.getMeasuredWidth(); | ||
break; | ||
} | ||
y += mh + dividerSize; | ||
} else { | ||
y += mh + dividerSize; | ||
i--; | ||
} | ||
|
||
x = 0; | ||
w = 0; | ||
mh = 0; | ||
lineCount = 0; | ||
} else { | ||
if (child.equals(view)) { | ||
find = true; | ||
} | ||
w += child.getMeasuredWidth() + dividerSize; | ||
if (!find){ | ||
x += child.getMeasuredWidth() + dividerSize; | ||
} | ||
mh = Math.max(mh, child.getMeasuredHeight()); | ||
lineCount++; | ||
} | ||
} | ||
|
||
int offsetX = Gravity.apply(Gravity.horizontal(getGravity()),width,lineCount == 0 ? w : w - dividerSize); | ||
int offsetY = Gravity.apply(Gravity.vertical(getGravity()),mh, view.getMeasuredHeight()); | ||
|
||
x += getPaddingLeft() + offsetX; | ||
y += getPaddingTop() + offsetY; | ||
return new Point(x,y); | ||
} | ||
|
||
@Override | ||
public void addChild(View view, ViewGroup.LayoutParams params) { | ||
LayoutParams newParams = new LayoutParams(params.width,params.height); | ||
newParams.from(params); | ||
super.addChild(view, newParams); | ||
} | ||
|
||
public static class LayoutParams extends ViewGroup.LayoutParams { | ||
|
||
public LayoutParams(int width, int height) { | ||
super(width, height); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters