1

Hey guys i have a problem. I made a button flashing animation by coding

     button7.setOnTouchListener(new View.OnTouchListener() {
               public boolean onTouch(View v, MotionEvent me) {
                    try{ button7.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.white,0,0);

  } else if (me.getAction() == MotionEvent.ACTION_UP) {
 button7.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.neun,0,0);

Which was very simple. Now the thing is, that this just works on one screen size, because the pictures dont get stretched. I made different layout XMLs for the different screen so can I just set the "android:onclick" (or something like that) in the XMLs so I can set a different picture for every size?

Thanks

I just tried messing around with "android:onClick" but achieved nothing.

user2161301
  • 674
  • 9
  • 22
  • Your code snippet doesn't make any sense...can you post the full snippet? – Tyler MacDonell Mar 21 '13 at 23:59
  • What the button now does, is just displaying the white res as long I have a finger on it. As I release it, the "old" picture gets loaded on the button. But please, don't care about this, I already said why this way is wrong. – user2161301 Mar 22 '13 at 00:14

1 Answers1

1

You should pay attention to selector element as a Drawable for your button. Then, you will not need any onClick()/onTouch() methods at all - all will be done automatically. Also, you should use .9 images to eliminate scaling problems for different screen sizes.

Prizoff
  • 4,486
  • 4
  • 41
  • 69
  • You are the man! Thanks dude! I didn't know about that, but somehow i knew that they had to implement something like that, now i even know what it is called like. – user2161301 Apr 01 '13 at 10:02
  • You're welcome! Also, if it answers your quetion, consider accepting this as answer - this will give some reputation both to you and me. Also, you can press "up" arrow near the answer, if it helped you. – Prizoff Apr 01 '13 at 10:29