【问题标题】:How to Call Drawable XML File in Picasso Library?如何在 Picasso 库中调用 Drawable XML 文件?
【发布时间】:2016-12-20 04:59:06
【问题描述】:

使用 XML 选择器为 Click 事件更改 Android 按钮更改图像。像这样。

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/start_button_pushed" />
    <item android:drawable="@drawable/start_button" />
</selector>

和这样的布局 XML 文件。

ma​​in_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"/>

现在。我计划使用毕加索图像库进行图像缓存。以避免内存不足错误。所以这是我的场景。这个怎么做。提前致谢。

【问题讨论】:

标签: android xml imageview picasso


【解决方案1】:
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;
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多