本文主要是介绍RadioGroup变为按钮工具条,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
xml设置
<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>
绑定监听的代码
//绑定监听器 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;}}});}
效果:
点击播放不断切换两个图片
转自:http://www.cnblogs.com/helloandroid/archive/2011/08/23/2151164.html
这篇关于RadioGroup变为按钮工具条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!