eclipse进行Android开发学习时:setImageResource(R.drawable.helloworld) 运行后却显示的是icon
packagecom.noha.test.HelloWdImg;importandroid.app.Activity;importandroid.os.Bundle;im...
package com.noha.test.HelloWdImg;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class HelloWdImg extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
/**Set the ContentView to the ImageView */
setContentView(HelloWorldImageView);
}
}
运行不报错 但是为什么显示的却是自带的icon.png那个机器人图片? 而不是我放的helloworld.png
drawable-hdpi drawable-hdpi drawable-mdpi 这三个文件夹里我都放了我新加的helloworld.png 图片啊
小弟分不多 请各位帅哥点拨啊~ 展开
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class HelloWdImg extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
/**Set the ContentView to the ImageView */
setContentView(HelloWorldImageView);
}
}
运行不报错 但是为什么显示的却是自带的icon.png那个机器人图片? 而不是我放的helloworld.png
drawable-hdpi drawable-hdpi drawable-mdpi 这三个文件夹里我都放了我新加的helloworld.png 图片啊
小弟分不多 请各位帅哥点拨啊~ 展开
6个回答
展开全部
不知道你是不是直接把图拖到drawable的文件夹,如果你用eclipse,你需要import图片到文件夹,然後可能需要重新clean一下以生成新的R文件,这样才能在R文件注册这个资源。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把代码改成这样试试
package com.noha.test.HelloWdImg;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class HelloWdImg extends Activity {
LinearLayout mLinearLayout;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
HelloWorldImageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
/**Set the ContentView to the ImageView */
mLinearLayout.addView(HelloWorldImageView);
setContentView(mLinearLayout);
}
}
package com.noha.test.HelloWdImg;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class HelloWdImg extends Activity {
LinearLayout mLinearLayout;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
HelloWorldImageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
/**Set the ContentView to the ImageView */
mLinearLayout.addView(HelloWorldImageView);
setContentView(mLinearLayout);
}
}
参考资料: http://wenwen.soso.com/z/q263966393.htm
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
LinearLayout mLinearLayout;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
}
}
这样应该可以
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
}
}
这样应该可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我试了一下可以啊,会不会是你的图片不好?换一张试试。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询