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

    }});
    }

    效果:

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

  • 相关阅读:
    javascript金额千分位的实现
    html中仿GroupBox效果与路径问题
    javascript获取表格的高度
    分布式系统的架构思路
    sharepoint2010 Reporting Services 集成注意
    Ext.MessageBox.updateProgress
    认识RFID
    Extjs 下拉ComboBox分页,图片,多行显示
    MVCFckEditor一些小问题
    MVCFckEditor
  • 原文地址:https://www.cnblogs.com/helloandroid/p/2151164.html
Copyright © 2011-2022 走看看