解決控件測量寬高問題
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
getWidth(4);
}
private void test(){
getWidth(1);
marqueeView.measure(0, 0);
getWidth(2);
marqueeView.post(new Runnable() {
@Override
public void run() {
getWidth(3);
}
});
}
private void getWidth(int a){
int width2 = marqueeView.getWidth();
int measuredWidth2 = marqueeView.getMeasuredWidth();
Log.e(a+"MainActivity-----",width2+"-----"+measuredWidth2);
}
//11-28 17:03:17.559 15990-15990/com.yc.cn.ycbanner E/1MainActivity-----: 0-----0
//11-28 17:03:17.567 15990-15990/com.yc.cn.ycbanner E/2MainActivity-----: 0-----760
//11-28 17:03:17.684 15990-15990/com.yc.cn.ycbanner E/3MainActivity-----: 960-----960
//11-28 17:03:17.685 15990-15990/com.yc.cn.ycbanner E/4MainActivity-----: 960-----960