I have a simple sample for TransitionDrawable, when I click on ImageView one picture goes to second picture. But how on next click go back from second picture to one?
image.setImageDrawable(mTransition);
mTransition.startTransition(1000);
Just an idea,it may work for you.
take another transition animation xml file and reverse the images
take a vriable
int v=2;
and inside onClick,
public void onClick(){
if(v%2==0){
image.setImageDrawable(mTransition1);
mTransition1.startTransition(1000);
v++;
}
else{
image.setImageDrawable(mTransition2);
mTransition2.startTransition(1000);
v++;
}
}
Related
I need some help,
I have one ImageButton that plays and stops a tune, I want the button to change to a stop symbol when playing and then back to a play symbol when stopped. So far I have the symbol and tune playing when the ImageButton is clicked the first time, but when it is clicked the second time, the tune stops but the image does not change, any advice?
mPlayTune.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (tuneMp.isPlaying()) {
tuneMp.stop();
tuneMp.prepareAsync();
mPlayTune.setImageResource(R.drawable.ic_av_play_arrow);
}else
tuneMp.start();
mPlayTune.setImageResource(R.drawable.ic_av_stop);
}
});
Couldn't you just make 2 objects and hide or show them by clicking them? It's not a clean implementation but for sure a workaround.
I solved it, it was simply changing
tuneMp.start();
mPlayTune.setImageResource(R.drawable.ic_av_stop);
to
mPlayTune.setImageResource(R.drawable.ic_av_stop);
tuneMp.start();
this way it sets the icon before hitting tuneMp.start();
I need to do a two image button with onClick.That two image button have to be located in same place.one image button is to start functionality for voice record and other image button is stop functionality for voice record.
I done a functionality exactly.My only problem is to use two image button for stop and start in same place.
I searched many tutorials and SO posts.But I didn't get it.
Anyone can help me with this.
Just use one button and the method setBackgroundResource of the ImageButton. use one and the same button and in the onClick method use this line:
yourButton.setBackgroundResource(R.drawable.startImg); //for start of the recording
and
yourButton.setBackgroundResource(R.drawable.stopImg); //for stop of the recording
if (myAudioRecorder==null) {
myAudioRecorder.start();
audioButton.setImageResource(R.drawable.stop);
} else if (myAudioRecorder != null) {
audioButton.setImageResource(R.drawable.record);
}
In my application, I have recording button. I want when user clicks on it each one second i change the background in order to simulate blinking. I created a handler and set it to 1 second therefore each one second this handler runs. Here i change the background. this my code:
mUpdateUITimerTask = new Runnable() {
public void run() {
// Simulating blinking for capture button
if(bolToggle) {
bolToggle = false;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record_blink));
} else {
bolToggle = true;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record));
}
mHandler.postDelayed(mUpdateUITimerTask, 1000);
}
};
When I run the app i see the changes but its not clear. buttons are like this:
When i run the application, red image is showing ok but for white image, it shows red image with a little white halo around it.
I tried to put captureButton.setBackgroundColor(Color.TRANSPARENT); before setting background but result was same.
any suggestion would be appreciated. Thank you.
Found the answer you need: https://stackoverflow.com/a/4852468/1352556
Basically you want an alpha animation. I believe this will make the entire button flash however, do you only want the red dot flashing?
I've just finished copying the android walkthrough for the gallery (http://developer.android.com/resources/tutorials/views/hello-gallery.html) and was wondering how I would go about having the thumbnail photo scale into a larger one within the onClickItem method.
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(ProjectPreview.this, "" + position, Toast.LENGTH_SHORT).show();
}
Currently it just shows the position as depicted in the Toast. Could someone point me in the right direction or show me a simple way?
Thanks in advance.
EDIT: Added this method and called it in the onItemClick sending it the position. And it works.
public void showLarger(int position){
ImageView image = (ImageView) findViewById(R.id.iv1);
image.setLayoutParams(new Gallery.LayoutParams(200, 100));
image.setScaleType(ImageView.ScaleType.FIT_XY);
image.setImageResource(mImageIds[position]);
}
Use a Dialog with a layout which contains an imageview, and set its source case the position you have and with the size you want.
I would use a Dialog. You can create a new activity and have an ImageView in its layout, and disguise that Activity as a Dialog. See this question for how to do all that: Android Image Dialog/Popup
As mentioned above, you can use a Dialog to display the larger image or you can just fire an intent that would start a regular Activity(You will have to add the dialog Theme to your Activity if you do it as described as above).
You'd have to do something like call v.getItemID(position) and store that in a String, then pass that into your next Activity.
Either way, you'll have to pass in some data to your Activty that will host the ImageView, and then use that data(path, uri, etc) to inflate your larger ImageView. Just don't forget to add the theme to your manifest if you want use the Dialog route.
I am making an app that has a scrolling screen like the homescreen style. I have implemented this solution:
Android Homescreen
It works great but I also want there to be buttons on each page that you can click to go to the next page but I just can't figure out how to do it! can someone help? I've been staring at this code for days now!
Thanks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UPDATE - HELP
I really don't understand how to get around the problem of calling the SetToScreen from the other activity, Can anyone help as if I try I do keep getting Static call errors.
Look at
public void setToScreen(int whichScreen) {}
Use this function to set to a screen on a click.
you should extend Draggablespace by adding a function to get the current space like:
public int getCurrentScreen() {
return this.mCurrentScreen;
}
then you can write your own functions in your activity like
public void nextScreen() {
draggableSpace.setToScreen(draggableSpace.getCurrentScreen() + 1));
}
The same for previous screen.
Now you only need to check if there is an additional screen waiting if you are going forward or backward.
(Of course draggableSpace is your object of the class draggablespace...not a static call!)