Android 如何在毕加索库中调用可绘制的XML文件?
Android按钮使用XML选择器更改单击事件的图像更改。像这样 StartButtonSelector.XMLAndroid 如何在毕加索库中调用可绘制的XML文件?,android,xml,imageview,picasso,Android,Xml,Imageview,Picasso,Android按钮使用XML选择器更改单击事件的图像更改。像这样 StartButtonSelector.XML <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/s
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/start_button_pushed" />
<item android:drawable="@drawable/start_button" />
</selector>
然后像这样布局XML文件
main_activity.xml
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/startButton"
android:layout_marginBottom="10dp"
android:layout_marginTop="8dp"
android:background="@drawable/start_btn_selector"/>
现在。我计划使用毕加索图像库进行图像缓存。以避免内存不足错误。这就是我的设想。如何做到这一点。提前谢谢 为此,您可以参考以下链接:对于缓存,Glide比毕加索更好。我已经提到了Glide。不使用毕加索。加载(R.drawable.start\u btn\u选择器)。进入(startBtn);你有没有试过这个:你可以参考这个链接:因为缓存Glide比毕加索好。我已经提到了Glide。不使用毕加索。加载(R.drawable.start\u btn\u选择器)。进入(startBtn);你试过这个吗:
ImageView imageView = (ImageView)findViewById(R.id. startButton)
Picasso.with(context).load(R.drawable.start_button).into(imageView);
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction()==MotionEvent.ACTION_DOWN){
// Button pressed state
Picasso.with(context).load(R.drawable.start_button_pushed).into(imageView);
}else if (motionEvent.getAction()==MotionEvent.ACTION_UP){
// Button released state
Picasso.with(context).load(R.drawable.start_button).into(imageView);
}
return true;
}
});