我一直在尝试找到一个可以执行 seekmark.markPlace() 的侦听器。该函数采用我的布局中定义的 seekBar 的尺寸和填充。当我从 onCreate 调用该函数时,它为 seekBar 的值返回 0。我需要一个可以在 onCreate 之外调用该函数的侦听器。该函数仅应在屏幕旋转时运行(当创建 layout-land 时)。
public class seekMark {
private int seekLength; // in pixels
private int seekLeftPad; // in pixels
private int seekBottomPad; // in pixels
private int trackLength; // in ms
public seekMark(){
seekLength = progressBar.getWidth();
seekLeftPad = progressBar.getPaddingLeft();
seekBottomPad = progressBar.getPaddingBottom();
trackLength = player.getDuration();
}
private int pxPerMs(){
return (seekLength/trackLength);
}
public void markPlace() throws XmlPullParserException, IOException {
Drawable marker = context.getResources().getDrawable(R.drawable.audio);
int y = seekBottomPad;
int x = 0;
int w = marker.getIntrinsicWidth();
int h = marker.getIntrinsicHeight();
int[] bmPos = markPxList(); // returns a list of px (from the left) read from a xml database
for(int i = 0; i <= bmPos.length; i++){
x = bmPos[i] + seekLeftPad;
marker.setBounds( x, y, x + w, y + h );
marker.draw( canvas );
}
}
}
是否可以像 onRotate() 之类的那样制作自己的听众?