Android help: About the Play/pause button in the player: use ImageButton to set the click Effect

Source: Internet
Author: User
Tags set background

============ Problem Description ============


Hello everyone, I have a problem recently:
As everyone knows, the play/Pause key in the player is the logic: when the user clicks on this key, if the current display is a "play" pattern, it will become a "pause" pattern, conversely, if the current "pause" pattern, will change to "play" pattern, so repeatedly ...
Now I'm working on this effect, and I'm doing it:
On the basis of the above basic effect, I also added the effect of the click Process, that is, when the point is also released when the wood, there will be a click effect (such as to add a halo effect to the current picture or something), this effect I was in the XML with selector tag implementation, on the code:
When on Play: (Xml_player_play.xml)
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "><itemandroid:state_pressed=" false "android:drawable=" @drawable/player_play_default "/>< Itemandroid:state_pressed= "true" android:drawable= "@drawable/player_play_pressed"/> <itemandroid:state_ Window_focused= "false" android:drawable= "@drawable/player_play_default"/></selector>


When you press pause: (xml_player_pause.xml)
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "><itemandroid:state_pressed=" false "android:drawable=" @drawable/player_pause_default "/>< Itemandroid:state_pressed= "true" android:drawable= "@drawable/player_pause_pressed"/> <itemandroid:state_ Window_focused= "false" android:drawable= "@drawable/player_pause_default"/></selector>


ImageButton XML file (omit code like ID, width, etc.):
<imagebutton android:background= "#0000" android:src= "@drawable/xml_player_play" Androi D:scaletype= "Centercrop"/>


The onclick () method is then implemented in the code to determine how the image should be changed:
if (Global.bt_play_play = = True) {Play.setbackgroundresource (r.drawable.xml_player_pause); Global.bt_play_play = false;} else if (Global.bt_play_play = = False) {Play.setbackgroundresource (r.drawable.xml_player_play); Global.bt_play_play = true;}

The Global.bt_play_play is a boolean static variable, which, by default, is true, which is used to determine whether a pattern is currently a divine horse or not.

It looks like there's a problem with the wood, but it works:
Just run up:
After clicking:
Click once more:

Why is it that there is an oval circle in it? And the picture changes, the previous picture did not disappear, coincident together?

============ Solution 1============


Before you set up the picture. Let's clear the picture first.
Why Ellipse? I don't know.
is not two pictures. Size (Height*width) is not the same. But the same layout is used. Like what. Automatic expansion.
And then it caused. Will there be an ellipse?

============ Solution 2============


<imagebutton
Android:background= "#0000"
android:src= "@drawable/xml_player_play"
Android:scaletype= "Centercrop"/>

Have src do not set background, background or src Delete to try
Logically your Java code is right ...

============ Solution 3============


Put the selector in the

<item
Android:state_window_focused= "false"
android:drawable= "@drawable/player_pause_default"/>

These are all removed.

Write the following pattern 414

<?xml version= "1.0" encoding= "UTF-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "false" android:drawable= "@drawable/button_add"/>
<item android:state_pressed= "true" android:drawable= "@drawable/button_add_pressed"/>
<item android:state_focused= "true" android:drawable= "@drawable/button_add_pressed"/>
<item android:drawable= "@drawable/button_add"/>
</selector>

============ Solution 4============


if (Global.bt_play_play = = True)
{
Play.setimageresource (R.drawable.xml_player_pause);
Global.bt_play_play = false;
}
Else
{
Play.setimageresource (R.drawable.xml_player_play);
Global.bt_play_play = true;
}

Android help: About the Play/pause button in the player: use ImageButton to set the click Effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.