Questions tagged [android-viewtreeobserver]

39 questions
16
votes
2 answers

Why we use ViewTreeObserver#addOnGlobalLayoutListener()

Why do we use ViewTreeObserver, please can anyone explain it? In below code creditsView is TextView object. By this whole code I understand that "this is to hide some text based on condition", but only thing is why we are using…
12
votes
9 answers

How to disable emojis programmatically in Android

I want to hide emojis and auto suggestions from keyboard programmatically. Its working in some Android devices but not in all devices. here's my code for hide auto suggestions: txtSingupemail.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER |…
Ruchir
  • 1,086
  • 4
  • 24
  • 48
9
votes
3 answers

Why does calling getWidth() on a View in onResume() return 0?

Everything I've read says you can't call getWidth() or getHeight() on a View in a constructor, but I'm calling them in onResume(). Shouldn't the screen's layout have been drawn by then? @Override protected void onResume() { super.onResume(); …
5
votes
2 answers

textView change to shorter text dynamically instead of ellipsize

I have this code: final ViewTreeObserver[] viewTreeObserver = {myAcco viewTreeObserver[0].addOnPreDrawListener( new OnPreDrawListener() { @Override public boolean onPreDraw() { int chipWidth = …
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
4
votes
3 answers

View draw complete callback

What event signifies that the draw of a View is complete? I know about ViewTreeObserver listeners, but I couldn't find the 'final' one, which indicates, that the job is done.
3
votes
0 answers

Detect ViewTreeObserver Global Layout last call

I've seen many questions (and answers) regarding ViewTreeObserver but none have completely answer the question/problem i'm facing. So here's what i have: I have some views being added programmatically inside a scrollview. After all the layout has…
Peddro
  • 1,105
  • 2
  • 9
  • 19
2
votes
1 answer

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 viewTreeObserver =…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
2
votes
2 answers

Setting ImageView width and height relative to text height

I have a ListView. On each row is an image and text. I want to scale image so it fits the row height i.e. image shouldn't cause the row height is bigger image height should be the same as the row height image width should be calculated so the…
user7232539
2
votes
0 answers

Avoid items from ViewTree onScrollChanged()

I am using ViewTreeObserver.OnScrollChangedListener to determine when ScrollView bottom has been reached. Here is my layout: //use as a banner //there are…
Bishan
  • 15,211
  • 52
  • 164
  • 258
2
votes
0 answers

By what i can replace ViewTreeObserver.OnComputeInternalInsetsListener that is declared as hidden?

I try to import in my library some android internal source code. however i have some trouble to import this part of code : private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = new…
zeus
  • 12,173
  • 9
  • 63
  • 184
2
votes
2 answers

How long is Android ViewTreeObserver alive?

I am working on an app which listens for View events like scrolling, layout drawn using ViewTreeObserver. ViewTreeObserver has a method to check if it's alive before doing anything eg. adding listeners. I have to reproduce the issue of dead / not…
Pradeep
  • 6,303
  • 9
  • 36
  • 60
2
votes
0 answers

Get soft keyboard's height without ViewTreeObserver

I am currently getting the height of the soft keyboard by using the ViewTreeObserver like: private final ViewTreeObserver.OnGlobalLayoutListener mKeyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public…
1
vote
0 answers

How do I access variables from a class of inner method in Java?

I have an object mPhotoView which is declared and defined in a class (outer class?) CrimeFragment. I want to access a variable defined in a method of method of mPhotoView. mPhotoView = (ImageView)v.findViewById(R.id.crime_photo); …
1
vote
0 answers

Recycler item_view height is changing after first initialisation in android

In recycler_view adapter class the following code is added for dynamically changing height of item_view override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskListViewHolder { val itemView =…
1
vote
2 answers

android view width is not bigger when a11y is changed to big font

I have some code that measure the width of an android textView and the text to display in it. final ViewTreeObserver[] viewTreeObserver = {myAccountView.getViewTreeObserver()}; viewTreeObserver[0].addOnPreDrawListener( new…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
1
2 3