Pages

Wednesday, May 19, 2010

Button to click Effects , Image Click effects in android

Last talked about how to make the effect of pressing the Button has also mentioned but in the end if we ask a few Button has this effect separately for each definition of a Button a *. xml is inconvenient for a bit today on the presentation about the practice of simplicity 
Ten One Design T1-AP25-102 Pogo Sketch Stylus for iPhone 3G, 3G S
[Code step] 

1. Preparing for two ImageButton required *. ico such as: 

Wrote 

play.ico: ImageButton-play of the static (not pressed) effects 
play_down.ico: ImageButton-play of the press effect 

pause.ico: ImageButton-pause of the static (not pressed) effects 
pause_down.ico: ImageButton-pause in pressing the effect of 

2. To build the layout there are two ImageButton 

(I am using "(" in place of "<" due to restriction.)
****************************************

(?xml version="1.0" encoding="utf-8"?>
(LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
(ImageButton  
        android:id="@+id/play"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    />
(ImageButton  
        android:id="@+id/pause"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    />
(/LinearLayout>
****************************************
Microsoft Office Home and Student 20073. Respectively, the definition of the name of easy reference View 
****************************************

public void initialView(){
        play = (ImageButton) findViewById(R.id.play);
        pause = (ImageButton) findViewById(R.id.pause);
    }
****************************************
4. For the ImageButton play, pause specify the default background 
****************************************
public void specifyBackground(){
play.setBackgroundResource(R.drawable.play);
pause.setBackgroundResource(R.drawable.pause);
}                                                                                      ****************************************



5. To ImageButton play, pause Registration onTouch () events and in accordance with its ID and state the specific background image specified 






****************************************

@Override
 public boolean onTouch(View v, MotionEvent event) {
                                // TODO Auto-generated method stub
                               switch(v.getId()){
                                case R.id.play:
                                        if(event.getAction() == MotionEvent.ACTION_DOWN){
                                                v.setBackgroundResource(R.drawable.play_down);
                                        }
                                        else if(event.getAction() == MotionEvent.ACTION_UP){
                                                v.setBackgroundResource(R.drawable.play);
                                        }
                                        break;
case R.id.pause:
if(event.getAction() == MotionEvent.ACTION_DOWN){
                                                v.setBackgroundResource(R.drawable.pause_down);
                                        }
                                        else if(event.getAction() == MotionEvent.ACTION_UP){
                                                v.setBackgroundResource(R.drawable.pause);
                                        }
                                        break;
                                        
                                
                                }
                                
                                return false;
                        }
                
        };
        
        play.setOnTouchListener(listener);
        pause.setOnTouchListener(listener);
****************************************
6. All the procedures as follows: 
****************************************
public class ButtonStyle3Usage extends Activity {
        ImageButton play,pause;    
        OnTouchListener listener;  
  /** Called when the activity is first created. */
    @Override   
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        initialView();

        specifyBackground();
        listener = new OnTouchListener(){

@Override
                        public boolean onTouch(View v, MotionEvent event) {
                                // TODO Auto-generated method stub
                                switch(v.getId()){
                                case R.id.play:
                                        if(event.getAction() == MotionEvent.ACTION_DOWN){
                                                v.setBackgroundResource(R.drawable.play_down);
                                        }
                                        else if(event.getAction() == MotionEvent.ACTION_UP){
                                                v.setBackgroundResource(R.drawable.play);
                                        }
                                        break;
                                
                                case R.id.pause:
                                        if(event.getAction() == MotionEvent.ACTION_DOWN){
                                                v.setBackgroundResource(R.drawable.pause_down);
                                        }
                                        else if(event.getAction() == MotionEvent.ACTION_UP){
                                                v.setBackgroundResource(R.drawable.pause);
                                        }
                                        break;
                                        
                                
                                }
                                
                                return false;
                        }
                
        };
        
        play.setOnTouchListener(listener);
        pause.setOnTouchListener(listener);
    }
    
    
    public void initialView(){
        play = (ImageButton) findViewById(R.id.play);
        pause = (ImageButton) findViewById(R.id.pause);
    }
    
    public void specifyBackground(){
        play.setBackgroundResource(R.drawable.play);
        pause.setBackgroundResource(R.drawable.pause);
    }
}
****************************************
14k Yellow and White Gold Crossover Hoop Earrings
7. Emulator to run Screenshot: Static 

No comments:

Post a Comment