cannot display an image with a do while in the OnCreate method
I'm trying to draw an image inside a do while in the OnCreate
method but it fails to show.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
drawElements();
}
public void drawElements(){
do{
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(80, 60);
params.setMargins(0, 0, 0, 0);
ImageView image = new ImageView(this);
personaje.setImageResource(R.drawable.image);
layout.addView(image, params);
setContentView(layout);
Log.i("MainActivity","here comes");
}while(!esc)
}
It's strange because it comes in the do while
, because the log shows constantly on the LogCat but the image does not show.
In fact, it fails to remove the status bar or the title of the application as 开发者_StackOverflow中文版specified in the onCreate
, but if I remove the do while it shows everything correctly.
Any suggestions?
You need to rethink your whole design. What you are doing here does not make any sense.
Your while loop is going to loop forever, blocking the UI thread. Thus, nothing will ever be displayed.
Instead, you should display a single image in onCreate
. Add a key listener or button listener that will change the image within the listener.
精彩评论