Answer the question
In order to leave comments, you need to log in
How to get ImageView size?
How can I get the size of an ImageView on application startup?
Answer the question
In order to leave comments, you need to log in
The ViewTreeObserver gives you the ability to hook into certain stages in the "life cycle" of a View, including the stage when the View's dimensions have been determined:
imageview.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//
// Тут вы пишите ваш код, который завязан на знание размера View
//
// А тут отсоединяете OnGlobalLayoutListener
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
imageview.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
imageview.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
The View class has getWidth and getHeight methods. Returns the width and height of your view in pixels.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question