2016-12-20 3 views
1

AndroidボタンXMLセレクタを使用してクリックイベントの画像の変更を変更します。このような。PicassoライブラリのDrawable 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/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"/> 

。私は画像のキャッシュにPicasso Image Libraryを使用する予定です。メモリエラーを回避する。これは私のシナリオです。これを行う方法。前もって感謝します。このリンクREFEREことができるため

+0

:http://stackoverflow.com/questions/21158425/picasso-load-drawable-resources-from-their-uri キャッシュグライドのためにはピカソよりも優れています。私はグライドを参考にしました。 –

+0

作業していないPicasso.with(this).load(R.drawable.start_btn_selector).into(startBtn); –

+0

これを試してみましたか:http://stackoverflow.com/questions/27010349/how-to-update-the-selectorstatelistdrawable-images-using-picasso –

答えて

0
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; 
    } 
}); 
+0

ありがとうございました@B Linさんの作品です。私を投票してください –

関連する問題