Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
Dmuasya
/
StickyNavLayout.java
Secret
Created
Dec 22, 2020
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Raw
StickyNavLayout.java
@Override
protected
void
onMeasure(
int
widthMeasureSpec,
int
heightMeasureSpec) {
//
For simple implementation, our internal size is always 0.
//
We depend on the container to specify the layout size of
//
our view. We can't really know what it is since we will be
//
adding and removing different arbitrary views and do not
//
want the layout to change as this happens.
setMeasuredDimension(getDefaultSize(
0
, widthMeasureSpec),
getDefaultSize(
0
, heightMeasureSpec));
}
public
static
int
getDefaultSize(
int
size,
int
measureSpec) {
int
result
=
size;
int
specMode
=
MeasureSpec
.
getMode(measureSpec);
int
specSize
=
MeasureSpec
.
getSize(measureSpec);
switch
(specMode) {
case
MeasureSpec
.
UNSPECIFIED
:
result
=
size;
break
;
case
MeasureSpec
.
AT_MOST
:
case
MeasureSpec
.
EXACTLY
:
result
=
specSize;
break
;
}
return
result;
}
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.