如何使通用的图像加载器加载图像按钮? [英] How to make universal image loader load image buttons?
问题描述
我'对不起,愚蠢的问题,但我'还是一个初学者。结果
采用通用的图像加载我': https://github.com/nostra13/Android-Universal - 图像 - 装载机
(Android的是,Eclipse)
和我不知道如何使它加载我的图像按钮(每布局近30 imagebuttons),我不希望我的形象只是希望它显示,因为它是在XML文件中的任何改变
所以,如果你能告诉我什么code,我应该键入的将是巨大的,谢谢
例如,如果我有这样的ImageButton在我的Java文件中设置了:
的ImageButton人员=(的ImageButton)findViewById(R.id.staff);
和我的Java文件称为MainActivity并将该图像保存在我的文件夹绘制怎么办。
我的code的一部分:
公共类MainActivity扩展活动实现OnClickListener {SP的Soundpool;
INT soundId;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)。 的setContentView(R.layout.activity_main); SP =新的Soundpool(5,AudioManager.STREAM_MUSIC,0);
soundId = sp.load(kh2hd.this,R.raw.btnclick,1); Picasso.with(本).load(R.drawable.staff).into(工作人员);
的ImageButton人员=(的ImageButton)findViewById(R.id.staffbtn); staff.setOnClickListener(本);}
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
开关(v.getId()){
案例R.id.staffbtn:
sp.play(soundId,1,1,0,0,1);
startActivity(新意图(android.intent.action.INFO));
打破;
从这里 下载毕加索库
将它添加到您的构建路径。导入这个库到code文件。
有关从网页的网址加载:
字符串的URL =http://example.com。Picasso.with(getApplicationContext())负载(URL).into(ImageView的);
有关从绘制负载:
Picasso.with(getApplicationContext())负载(R.drawable.imageFile).into(ImageView的)。
下面,ImageView的是您正在使用重新present的ImageView变量的名称。例如:
ImageView的ImageView的=(ImageView的)findViewById(R.id.ImageView1);
如果您正在使用的ImageButton,变化的ImageView变量的ImageButton变量
的ImageButton的ImageButton =(的ImageButton)findViewById(R.id.imageButton);
注意,我传递的变量名。
I'am sorry for the dumb question but I'am still a beginner.
I'am using universal image loader : https://github.com/nostra13/Android-Universal-Image-Loader
(Android, Eclipse)
and I don't know how to make it load my image buttons(nearly 30 imagebuttons per layout), I don't want to change anything in the image I just want it to display it as it is in the xml file.
So if you could tell me what code should I type that would be great, Thanks
for example if I have this ImageButton set up in my java file:
ImageButton staff = (ImageButton) findViewById(R.id.staff);
and my java file is called MainActivity and this image is saved in my drawable folder what should I do.
a part of my code:
public class MainActivity extends Activity implements OnClickListener {
SoundPool sp;
int soundId;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
soundId = sp.load(kh2hd.this, R.raw.btnclick, 1);
Picasso.with(this).load(R.drawable.staff).into(staff);
ImageButton staff = (ImageButton) findViewById(R.id.staffbtn);
staff.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.staffbtn:
sp.play(soundId, 1, 1, 0, 0, 1);
startActivity(new Intent("android.intent.action.INFO"));
break;
Download Picasso library from here
Add it to your build path. Import this library to your code file.
For loading from web url:
String url = "http://example.com"
Picasso.with(getApplicationContext()).load(url).into(imageView);
For loading from drawable:
Picasso.with(getApplicationContext()).load(R.drawable.imageFile).into(imageView);
Here, imageView is the name of variable you are using to represent ImageView. Eg.
ImageView imageView = (ImageView) findViewById(R.id.ImageView1);
If you are using ImageButton, change imageView variable to imageButton variable
ImageButton imageButton = (ImageButton)findViewById(R.id.imageButton);
Note that I am passing variable name.
这篇关于如何使通用的图像加载器加载图像按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!