Comments (8)
The values between getMeasuredHeight/Width and getHeight/Width don't have to be same as in explained in the documentation.
Also I believe you don't have to use the getMeasuredHeight/Width method in your app because it's used for the layout pass (done within the library).
So please use getHeight instead. If there is an issue in that method, please report an issue.
from flexbox-layout.
Hello,
To clarify, I said that getHeight() and getMeasuredHeight() were returning the same value when they should not have been, not that they should have been returning the same value. This is the issue I was trying to report. If the FlexboxLayout is set to wrap_content in a RelativeLayout that is set to a fixed height, and the FlexboxLayout contains enough items to exceed the fixed height of the RelativeLayout, it is my understanding that getMeasuredHeight() and getHeight() should return different values, but they are not.
My app needs to get the measured height of the FlexboxLayout in order to move/resize some sibling views, since cyclic dependencies would arise if attempting to use only RelativeLayout layout parameters.
To work around this issue, I have resorted to measuring the size of each line and dividers and summing them up, but a fix for getMeasuredHeight() would be better.
from flexbox-layout.
Hi,
If the FlexboxLayout is set to wrap_content in a RelativeLayout that is set to a fixed height, and the FlexboxLayout contains enough items to exceed the fixed height of the RelativeLayout, it is my understanding that getMeasuredHeight() and getHeight() should return different values,
Actually this is not correct.
Even if the length of the FlexboxLayout is set to wrap_content
and the parent RelativeLayout has a fixed height, it doesn't mean the getMesuredHeight and getHeight should return the different values.
Again, I think getMeasuredHeight is not meant to be used for outside of the view itself.
Please consider another approach.
from flexbox-layout.
Sorry to disagree, but from the documentation you linked:
The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().
A natural follow up question is, what exactly does "wants to be" mean? The answer is found by following the link to the Layout section. In the case of layout_height being set to wrap_content:
WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding).
(emphasis mine)
So according to this, if the content would make its own container bigger than its container's container (which in my case has a fixed height), getMeasuredHeight() should return a number bigger than the number returned by getHeight().
Granted, the documentation for getMeasuredHeightAndState(), which getMeasuredHeight() references, does say:
This should be used during measurement and layout calculations only. Use getHeight() to see how wide a view is after layout.
In my specific case I am actually trying to get the measured height of the view during layout (in OnGlobalLayoutListener.OnGlobalLayout()). The above documentation seems to indicate that getMeasuredHeight() should return the height the view wants to be regardless of its container's size at this point in time. Many stack overflow answers recommend this method for getting this measurement, for any view in general. If this is wrong as you say, then I suppose that the View documentation needs updating, but I find it more likely that FlexboxLayout has this implemented incorrectly. Please reconsider your closing of this issue.
from flexbox-layout.
Ok so could you share the example xml of this?
FlexboxLayout is set to wrap_content in a RelativeLayout that is set to a fixed height, and the FlexboxLayout contains enough items to exceed the fixed height of the RelativeLayout
I'll check if it's not the intended behavior.
from flexbox-layout.
Sure thing, and thanks for your consideration.
A direct paste of my layout xml is difficult since the relevant sections are broken up into 2 xml files, the RelativeLayout is actually a custom view in my case, and its contents are dynamically inflated. So instead I'll just create an example here with similar parameters:
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp">
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:alignItems="flex_start"
app:alignContent="center"
app:showDivider="middle"
app:dividerDrawable="@android:drawable/btn_dialog">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
</com.google.android.flexbox.FlexboxLayout>
</RelativeLayout>
Now in onCreate() if you do:
flexBox.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.d("flex", "measured height = " + flexBox.getMeasuredHeight());
Log.d("flex", "height = " + flexBox.getHeight());
}
});
I think you would see the same value logged twice.
from flexbox-layout.
Thanks for pasting the xml.
Checked that it was an intended behavior that the getMeasuredHeight and getHeight return the same value.
Because the value set to the measured height takes the spec parameters imposed by its parent (passed as widthMeasureSpec and heightMeasureSpec from the parent) into account as well as the value for getHeight.
If you replace the FlexboxLayout with LinearLayout, you can also check that getMeasuredHeight and getHeight return the same value.
(I tried this xml)
<RelativeLayout android:layout_width="200dp"
android:layout_height="200dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/flexbox_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:drawable/btn_dialog"
android:showDividers="middle"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/sym_def_app_icon"/>
</LinearLayout>
</RelativeLayout>
from flexbox-layout.
Ah, then I suppose it is the View documentation that needs updating. I'm sorry I didn't simply check the behavior of other built-in Android ViewGroups before opening this issue. Then all this back and forth could have been avoided. Thank you very much for looking into it.
from flexbox-layout.
Related Issues (20)
- Flexbox layout manager not scrollable
- indexInFlexLine is not consistent in onNewFlexItemAdded() method
- Android Studio Integration
- Add gap attribute HOT 3
- Wrong placement
- FlexboxLayoutManager.computeScrollOffset(); It is wrong to be equal to 0 HOT 1
- [FE] page 분기처리
- RecycleView nests RecycleView, and the internal RecycleView uses FlexboxLayoutManager(context, FlexDirection.ROW, FlexWrap.WRAP), when the number of items is large, it cannot be displayed completely (for example, only 30 items are displayed for 50 items, and they are not displayed after exceeding one screen) HOT 4
- ComposeView in flexbox crashes, because it is not attached when measured
- FlexboxLayoutManager child item margin is wrong when flex-direction is column
- How can i use this library in jetpack compose HOT 2
- Flaxbaox layout
- Playground doesn't build in latest Android Studio Flamingo HOT 3
- FlexboxLayoutManager does not recycle views with Navgraph HOT 3
- Is there possible to set "needsToFill" not only mContext.getResources().getDisplayMetrics().heightPixels?
- java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1 HOT 1
- FlexBoxLayoutManager with RecyclerView causes multiple items to refresh on calling notifyItemChanged
- First party support for Compose UI
- Support for Constraints of Rows & Columns
- Setting flex box percent to zero behaves differently than in CSS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flexbox-layout.