Wednesday, October 3, 2012

[android-developers] Re: width of my TextureView

At the point you're querying for the width/height the layout hasn't really been laid (those are not done right after creation of a view), you've never really specified for that view any layout parameters (why are you not using an xml layout anyhow?) and you didnt define any content for it, so what exactly is supposed to be measured?

Assuming you do all of that and when running the app the TextureView is showing properly as you want it to show, then you can figure out the width. The best method i've find is using a GlobalLayoutListener 

ViewTreeObserver vto = mTextureView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
@Override
public void onGlobalLayout(){
                                 //at this point you'll know its height and width, so use them here
ViewTreeObserver obs =   mTextureView .getViewTreeObserver();
obs.removeGlobalOnLayoutListener(this); //so it wouldn't be called again
}
});


On Tuesday, October 2, 2012 8:07:06 PM UTC+2, bob wrote:
Can someone help me see how to figure out the width of my TextureView?

I tried this, but I got zeros (in the_width and the_height):



protected void onCreate(Bundle savedInstanceState) {

mTextureView = new TextureView(this);

setContentView(mTextureView);

int the_width = mTextureView.getWidth();
int the_height = mTextureView.getHeight();

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate