zoukankan      html  css  js  c++  java
  • RadioGroup变为按钮工具条

    xml设置
    View Code
    <RadioGroup android:id="@+id/MusicList_RadioGroup"
    android:orientation
    ="horizontal" android:layout_alignParentBottom="true"
    android:layout_width
    ="match_parent" android:layout_height="wrap_content"
    android:padding
    ="2.0dip"
    android:background
    ="@drawable/radiogroup_bg"
    >

    <RadioButton android:id="@+id/MusicList_RadioGroup_next"
    android:drawableLeft
    ="@drawable/radiogroup_next"
    android:text
    ="@string/Text_radiogroup_next"
    android:textSize
    ="15.0dip"
    android:layout_weight
    ="1.0" android:button="@null"
    android:layout_width
    ="wrap_content" android:layout_height="wrap_content"
    />
    <RadioButton android:id="@+id/MusicList_RadioGroup_playAndpuse"
    android:drawableLeft
    ="@drawable/radiogroup_play"
    android:text
    ="@string/Text_radiogroup_play"
    android:textSize
    ="15.0dip"
    android:layout_weight
    ="1.0" android:button="@null"
    android:layout_width
    ="wrap_content" android:layout_height="wrap_content"
    />
    <RadioButton android:id="@+id/MusicList_RadioGroup_previous"
    android:drawableLeft
    ="@drawable/radiogroup_previous"
    android:text
    ="@string/Text_radiogroup_previous"
    android:textSize
    ="15.0dip"
    android:layout_weight
    ="1.0" android:button="@null"
    android:layout_width
    ="wrap_content" android:layout_height="wrap_content"
    />
    </RadioGroup>

    绑定监听的代码  

    View Code
            //绑定监听器
    MusicListTable_RadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
    public void onCheckedChanged(RadioGroup arg0, int rid) {
    switch(rid)
    {
    case R.id.MusicList_RadioGroup_next://下一首
    break;
    case R.id.MusicList_RadioGroup_previous://上一首
    break;
    case R.id.MusicList_RadioGroup_playAndpuse://播放或暂停
    if(isPlaying)
    {
    Drawable dr
    = res.getDrawable(R.drawable.radiogroup_play);
    //setBounds如果不设置的话setCompoundDrawables就会没有图片显示出来,所以一定要设置一次
    dr.setBounds(0, 0, dr.getMinimumWidth(), dr.getMinimumHeight());
    palyAndpuse.setCompoundDrawables(dr,
    null,null, null);//为RadioButton设置图片,左右上下对应xml的android:drawableLeft="@drawable/XXX"
    isPlaying=false;
    }
    else
    {
    Drawable dr
    = res.getDrawable(R.drawable.radiogroup_puse);
    dr.setBounds(
    0, 0, dr.getMinimumWidth(), dr.getMinimumHeight());
    palyAndpuse.setCompoundDrawables(dr,
    null,null, null);
    isPlaying
    =true;
    }
    arg0.clearCheck();
    //清除选择,如果不清除的话不能重复选择同一个Radiobutton
    break;
    }

    }});
    }

    效果:

    点击播放不断切换两个图片  

  • 相关阅读:
    桂林印象
    快变
    近期的事
    *C#中使用ref和out一点认识!*
    *在框架集页面放置TreeView控件时页面跳转的问题解决*
    *无法找到脚本库的问题*
    *Ajax.Net快速入门*
    *网页过期*
    *Prototype开发笔记*
    *正则表达式*
  • 原文地址:https://www.cnblogs.com/helloandroid/p/2151164.html
Copyright © 2011-2022 走看看