Java 用于确定图像属性的Android本机API(getWidth等)返回错误值

Java 用于确定图像属性的Android本机API(getWidth等)返回错误值,java,android,Java,Android,在Android中,当试图获取/设置图像属性时,我将图像属性设置为零,我猜这不是一个正确的值。请帮我做这个。以下是代码摘录: 代码 public class CumulativeGoalProgress extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cumulative

在Android中,当试图获取/设置图像属性时,我将图像属性设置为零,我猜这不是一个正确的值。请帮我做这个。以下是代码摘录:

代码

public class CumulativeGoalProgress extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cumulative_goals);
    showCumulativeGoalProgress();
    }


private void showCumulativeGoalProgress(){

ImageView wellnessBarIndicator =     (ImageView)findViewById(R.id.iv_welness_bar_indicator);

Log.e("Ravi", "progBarImage getBaseline = " + progBarImage.getBaseline());
Log.e("Ravi", "progBarImage getHeight = " + progBarImage.getHeight());
Log.e("Ravi", "progBarImage getMeasuredHeight = " + progBarImage.getMeasuredHeight());
Log.e("Ravi", "progBarImage getMeasuredWidth = " + progBarImage.getMeasuredWidth());
Log.e("Ravi", "progBarImage getWidth = " + progBarImage.getWidth());
Log.e("Ravi", "progBarImage getBottom = " + progBarImage.getBottom());
Log.e("Ravi", "progBarImage getLeft = " + progBarImage.getLeft());
Log.e("Ravi", "progBarImage getNextFocusLeftId = " + progBarImage.getNextFocusLeftId());
Log.e("Ravi", "progBarImage getPaddingLeft = " + progBarImage.getPaddingLeft());
Log.e("Ravi", "progBarImage getPaddingTop = " + progBarImage.getPaddingTop());
}
}
XML中定义的图像视图

<ImageView
    android:id="@+id/iv_welness_bar_indicator"
    android:layout_marginTop="119px"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:background="@drawable/vis_wellness_bar_indicator"
    />

vis_wellness_bar_indicator是PNG格式的源图像文件


我做错了什么?

发生的事情是,在
onCreate
阶段,视图尚未构建,因此图像尚未加载到ImageView中。稍后调用相同的代码,例如在
OnDraw
OnSizeChanged
方法上调用