Linked Questions
47 questions linked to/from Determining the size of an Android view at runtime
6 votes
2 answers
18k views
Get parent Width and Height [duplicate]
I've create a custom view based on LinearLayout and I need to calculate the layout width and height according to the parent view but each time I use ((View)this.getParent()).getMeasuredWidth() I got 0 ...
3 votes
2 answers
4k views
Dynamically calculate size of View elements [duplicate]
I have a unknown number of TextView elements some EditText elements and so on, that are all placed in one linear layout... And I want to calculate the height of the layout at run time so I can get the ...
0 votes
1 answer
152 views
How can I find the actual width of a view if the XML width attribute is declared as "0dp"? [duplicate]
I have an EditText that has a start and end constraint in a Constraint Layout, along with a width that is declared with a "0dp" in the XML. I am trying to figure out how to obtain the width of the ...
388 votes
23 answers
470k views
Height of status bar in Android [duplicate]
What's the height of the status bar in Android? Is it always the same? From my measurements it seems that it's 25dp, but I'm not sure if it has the same height on all platforms. (I want to know this ...
91 votes
19 answers
154k views
Get height and width of a layout programmatically
I have designed an layout in which LinearLayout has 2 children LinearLayout and FrameLayout and in each child I put different views. I just wanted to measure height and width of FrameLayout so that I ...
81 votes
14 answers
80k views
Text with gradient in Android
How would I extend TextView to allow the drawing of text with a gradient effect?
129 votes
5 answers
186k views
FloatingActionButton example with Support Library
Recently, I read these posts: Android Design Support Library Android Support Library, revision 22.2.0 FloatingActionButton But, none of them give me a detail example about creating a new ...
77 votes
5 answers
48k views
OnGlobalLayoutListener: deprecation and compatibility
I have to use an OnGlobalLayoutListener object and then to remove the listener, I had a problem with deprecated methods that I resolve with following code. protected void onCreate(Bundle ...
41 votes
7 answers
36k views
If I call getMeasuredWidth() or getWidth() for layout in onResume they return 0
If I call getMeasuredWidth() or getWidth() for layout in onResume they returns 0. I think that view it's not drawn yet in this moment. Also I think that I need to put getMeasuredWidth() or getWidth()...
47 votes
7 answers
33k views
How to get line count of textview before rendering?
How can I get the number of lines a string will take up in a TextView before it is rendered. A ViewTreeObserver will not work because those are only fired after it is rendered.
23 votes
1 answer
12k views
LinearLayout height in onCreate is 0
I'm trying to dynamically adjust the height of my rows depending on the (screen height - my layout height) / list.size. Unfortunately in the onCreate method the layout height returns null (not so ...
16 votes
5 answers
30k views
view.getViewTreeObserver().addOnGlobalLayoutListener leaks Fragment
When I use the GlobalLayoutListener to see if the softKeyboard is opened or not the fragment is not garbageCollected anymore after it is destroyed. What I do: I remove the Listener in the onDestroy() ...
9 votes
5 answers
18k views
android get adMob banner height when appears
I am adding an adMob banner to my app successfully. When banner appears I need to get its height in order to resize all layout elements. I am using the event onReceivedAd, that is properly fired. ...
10 votes
3 answers
8k views
Bound a View to drag inside RelativeLayout
I have created a draggable view inside RelativeLayout. But it seems to go beyond the RelativeLayout. I simply want to make a View draggable inside ViewGroup And this view is draggable according to ...
7 votes
4 answers
2k views
Real custom shape of button
Given any shape (either filled circle, star, triangle, bitmap with transparent areas, etc.) I would like to know if it's possible (using the latest Android API) to know if the user has clicked on the ...