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;
    }

    }});
    }

    效果:

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

  • 相关阅读:
    MySQL 多列索引优化小记
    Spring MVC + Security 4 初体验(Java配置版)
    Java程序通过代理访问网络
    Spring RESTful + Redis全注解实现恶意登录保护机制
    WinSCP 中普通用户以 root 身份登录 Linux
    Linux下修改系统时区
    Git如何检出指定目录或文件
    朴素贝叶斯
    console.log 被重写覆盖以后如何恢复
    MongoDB 基础命令使用学习记录
  • 原文地址:https://www.cnblogs.com/helloandroid/p/2151164.html
Copyright © 2011-2022 走看看