Version 2.0
xml file
android: layout_width = "fill_parent"
android: layout_height = "fill_parent">
java file
package slash.UISample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class ImageViewSample extends Activity {
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
ImageView iv1;
iv1 = (ImageView) findViewById (R.id.UIimg1);
iv1.setImageResource (R.drawable.slash);
setContentView (iv1);
}
}
slash.png res files are also placed under three drawable folder inside the
When running an error. . Used to be good, do not know why it
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
What is wrong? Phrase error, the error posted
Reply:
Must first setContentView (R.layout your xml file name.); To findViewById (R.id.UIimg1);
Reply:
You can run up, but tips
The application UISample (process slash.UISample) has stopped unexpectedly.please try it again
Reply:
Oh, wrong
ImageView iv1;
iv1 = (ImageView) findViewById (R.id.UIimg1) ;/ / call findViewById premise is already calling setContentView, ie the interface layout has been created
iv1.setImageResource (R.drawable.slash);
setContentView (iv1);
So to this:
setContentView (R.id.layout) ;/ / layout.xml is the layout of the interface is your xml file
ImageView iv1 = (ImageView) findViewById (R.id.UIimg1);
iv1.setImageResource (R.drawable.slash);
Reply:
4th floor with a method not an error, but the picture does not show it
Reply:
I do not know if Eclipse is a problem. . .
ImageView iv = new ImageView (this);
iv.setImageResource (R.drawable.icon);
setContentView (iv);
This code can be displayed before, not now also shows
Reply:
Is not a version of the problem? You try on 1.6 and 2.2
Reply:
Try replacing setBackgroundResource
Reply:
1.5 normal can be displayed
ImageView iv = new ImageView (this);
iv.setImageResource (R.drawable.icon);
setContentView (iv);
2.0 will not show it. . . . .
Reply:
Can you give an example of a 2.0 normal display pictures of it. . . .
Reply:
I also use the 2.0 can not display pictures.
No comments:
Post a Comment