Linked Questions
117 questions linked to/from View's getWidth() and getHeight() returns 0
0 votes
1 answer
1k views
getWidth() method returns 0
I am building an activity that shows two horizontal scroll views. The top one holds large images while the lower one holds the thumbnails of those images. When the user clicks on a thumbnail the upper ...
-1 votes
4 answers
615 views
RelativeLayout getWidth returns zero
First, I know this is a duplicate of other question but I couldn't manage to fix it so I created my own question for help. I am trying to get the RelativeLayout width, it was successful at first but I ...
1 vote
2 answers
917 views
How to get position X, Y of added view regardless of device screen size
I would like to get position X or Y of view (ie button) programmatically but in solutions from link (https://blog.takescoop.com/android-view-measurement-d1f2f5c98f75) returned values are wrong. I ...
0 votes
1 answer
829 views
Call getMeasuredWidth() or getWidth() for RecyclerView return 0 on data binding
I'm using data binding to setup a RecyclerView. Here is the binding adapter: fun setRecyclerDevices(recyclerView: RecyclerView, items: List<Device>, itemBinder: MultipleTypeItemBinder, ...
1 vote
2 answers
771 views
How to make button width equal to other button with the longer text
I have a few buttons with different text length. I'd like to make all buttons equal to the button with the longest text. Their width is android:layout_width="wrap_content" So the buttons have ...
0 votes
2 answers
773 views
Get PopupWindow height which has been set to WRAP_CONTENT
Here's my code: val inflater = LayoutInflater.from(this) val popupView = inflater.inflate(R.layout.small_player, null) val popupWindow = PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ...
0 votes
1 answer
716 views
How to know size of progress bar?
I want to place spinning wheel progress bar at (x, y) location in relative layout. To do that, I have to know the size of progress bar. How do I know size of progress bar? Is there better way than ...
1 vote
1 answer
715 views
[Android / Kotlin]: When are views initialized in lifecycle?
I need to know the size of a Button (or any other view). But none of the procedures in lifecycle (onCreate, onStart, OnResume) seem to know it, as the Button seems not yet to be initialized! ... ...
2 votes
1 answer
520 views
linear layout (View) Size in android
In my application i have gridview in linearlayout. Due to different sizes of screen, i want to calculate the width of the gridview's container (which in linearlayout) and then i will decide, how many ...
0 votes
1 answer
493 views
setTranslationY not initialized correctly
I created two short methods to help me to show or hide a view when a certain checkbox is checked. I have a Init method, in which I initialize a checkbox and a view, and a toggle method that is called ...
2 votes
1 answer
629 views
android view getWidth() returns 0 even in onPreDraw()
Based on answers in SOF, like this I have tried to measure the view late enough (onPreDraw) unlike the question opener in the above question link. I have this code: ViewTreeObserver ...
0 votes
1 answer
410 views
How Get width of a view using getWidth()?
How i can get Width or Height of a View in Android ? when using getWidth() getHeight() methods they are returning 0 and another sub question is getWidth() return value in dp or px ..
0 votes
1 answer
241 views
getHeight() doesn't get the height of the layout
I'm going to use dialog fragments. There is an item called writing_comment_item.xml in the dialogfragment, and I want to set the height of 5 items. I used the inflate() function, I used getHeight() to ...
2 votes
1 answer
502 views
Best practice for getting View dimensions, possibly before they are drawn to screen
I've seen a ton of different questions and answers to the problems people are having with retrieving height and width of views, particularly this thread. The following are mentioned methods to ...
0 votes
2 answers
383 views
Android adapter parent width = 0
maybe I'm tired but I miss something in what's happening in my code. I have an activity with fragments. My activity HomeActivity calls a webservice to fill a List (my business object), it does this ...