Linked Questions
117 questions linked to/from View's getWidth() and getHeight() returns 0
7 votes
1 answer
15k views
How to get fragment width? [duplicate]
Here is my layout.I need to get the width in CategoryFragment. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:...
4 votes
4 answers
2k views
RelativeLayout.getWidth returning 0 when layout width is 720 [duplicate]
I'm trying to learn the basics of android and when I call RelativeLayout.getWidth I get 0 as a value instead of the expected size of the layout. I have a RelativeLayout filling my screen: <...
0 votes
1 answer
629 views
getWidth() returns 0 in onCreate [duplicate]
I have this code : @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); content = (RelativeLayout) ...
2 votes
0 answers
141 views
Calling View.getTop() in Robolectric always returns 0 [duplicate]
I'm trying to verify the position of a View on screen but View.getTop or View.getLocationOnScreen() will always return 0. View.getHeight() is greater than 0 and appears to be correct. Is this a ...
0 votes
1 answer
94 views
About getting the width of a view from onResume() [duplicate]
When Activity onResume() is called, it indicates that the app is in the foreground, is visible, and is in a state of interacting with the user. However, when the method is executed for the first time, ...
0 votes
1 answer
78 views
Why view heights are zero in onCreate [duplicate]
I am trying to pass in view height as a max value for an animation inside onCreate to a custom gesture listener: @Override protected void onCreate(Bundle savedInstanceState) { ...
504 votes
8 answers
342k views
Android basics: running code in the UI thread
In the viewpoint of running code in the UI thread, is there any difference between: MainActivity.this.runOnUiThread(new Runnable() { public void run() { Log.d("UI thread", "I am the UI ...
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 ...
71 votes
6 answers
61k views
getHeight returns 0 for all Android UI objects
I'm building a UI, and it's all static defined in the XML. All of it has weights all over the place, and while it looks right, I wanted to see that things actually have the right height and all. The ...
30 votes
4 answers
87k views
Add Icons+Text to TabLayout
I am working on a screen which contains Three tabs I am trying to add an icon with My text in tabs and i want the image to be upper the text and there should be some space between them it is my code. ...
27 votes
2 answers
31k views
how to get the width of textView in android
This is the code what i am using... <TextView android:id="@+id/textView" android:layout_width="100dp" android:layout_height="40dp" android:text="AMIT KUMAR" /> and here is a ...
23 votes
8 answers
49k views
View's getWidth() and getHeight() returning 0
I have looked at the similar questions and tried their solutions, but it didn't work for me. I'm trying to read width of an imageView, but it is returning 0. Here is the code: public class ...
26 votes
6 answers
24k views
Get content view size in onCreate
I'm looking for a good way to measure the dimensions of the actual content area for an activity in Android. Getting display always works. Simply go like this: Display display = getWindowManager()....
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 ...
18 votes
2 answers
38k views
Android setting position of horizontal scrollview
I am trying to set the position of the horizontal scrollview so it corresponds with the button that is pushed. I've tried using this to set it unsuccessfully: HorizontalScrollView hsv = (...